Skip to content

Commit 05d041c

Browse files
committed
fix(StyleStore): fix stale reference leading to memory leak
stale reference... Update StyleStore.ts
1 parent 149cb11 commit 05d041c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/base/src/stores/StyleStore.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ function getSnapshot(): IStyleStore {
3939

4040
function subscribe(listener: () => void) {
4141
const listeners = getListeners();
42-
STORE_LOCATION[getStyleStoreListenersSymbol()] = [...listeners, listener];
42+
listeners.push(listener);
43+
4344
return () => {
44-
STORE_LOCATION[getStyleStoreListenersSymbol()] = listeners.filter((l) => l !== listener);
45+
const updatedListeners = getListeners();
46+
const index = updatedListeners.indexOf(listener);
47+
if (index !== -1) {
48+
updatedListeners.splice(index, 1);
49+
}
4550
};
4651
}
4752

0 commit comments

Comments
 (0)