diff --git a/packages/base/src/stores/StyleStore.ts b/packages/base/src/stores/StyleStore.ts index 7f302dc5c10..5490c8a4e38 100644 --- a/packages/base/src/stores/StyleStore.ts +++ b/packages/base/src/stores/StyleStore.ts @@ -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); + } }; }