Skip to content

Commit

Permalink
fix(StyleStore): fix stale reference leading to memory leak (#6651)
Browse files Browse the repository at this point in the history
Fixes #6649
  • Loading branch information
Lukas742 authored Nov 22, 2024
1 parent b630a80 commit b51cb24
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/base/src/stores/StyleStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ function getSnapshot(): IStyleStore {

function subscribe(listener: () => void) {
const listeners = getListeners();
STORE_LOCATION[getStyleStoreListenersSymbol()] = [...listeners, listener];
listeners.push(listener);

return () => {
STORE_LOCATION[getStyleStoreListenersSymbol()] = listeners.filter((l) => l !== listener);
const updatedListeners = getListeners();
const index = updatedListeners.indexOf(listener);
if (index !== -1) {
updatedListeners.splice(index, 1);
}
};
}

Expand Down

0 comments on commit b51cb24

Please sign in to comment.