Skip to content

Commit 12d5cb6

Browse files
fix: scope internal style store per Web Components runtime (#6319)
fixes #6315
1 parent f5b5c8a commit 12d5cb6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

packages/base/src/stores/StyleStore.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
const STORE_SYMBOL_LISTENERS = Symbol.for('@ui5/webcomponents-react/StyleStore/Listeners');
2-
const STORE_SYMBOL = Symbol.for('@ui5/webcomponents-react/StyleStore');
1+
import { getCurrentRuntimeIndex } from '@ui5/webcomponents-base/dist/Runtimes.js';
2+
3+
globalThis['@ui5/webcomponents-react'] ??= {};
4+
const STORE_LOCATION = globalThis['@ui5/webcomponents-react'];
5+
6+
function getStyleStoreListenersSymbol() {
7+
return Symbol.for(`@ui5/webcomponents-react/StyleStore-${getCurrentRuntimeIndex()}/Listeners`);
8+
}
9+
10+
function getStyleStoreSymbol() {
11+
return Symbol.for(`@ui5/webcomponents-react/StyleStore-${getCurrentRuntimeIndex()}`);
12+
}
313

414
interface IStyleStore {
515
staticCssInjected: boolean;
@@ -12,8 +22,8 @@ const initialStore: IStyleStore = {
1222
};
1323

1424
function getListeners(): Array<() => void> {
15-
globalThis[STORE_SYMBOL_LISTENERS] ??= [];
16-
return globalThis[STORE_SYMBOL_LISTENERS];
25+
STORE_LOCATION[getStyleStoreListenersSymbol()] ??= [];
26+
return STORE_LOCATION[getStyleStoreListenersSymbol()];
1727
}
1828

1929
function emitChange() {
@@ -23,15 +33,15 @@ function emitChange() {
2333
}
2434

2535
function getSnapshot(): IStyleStore {
26-
globalThis[STORE_SYMBOL] ??= initialStore;
27-
return globalThis[STORE_SYMBOL];
36+
STORE_LOCATION[getStyleStoreSymbol()] ??= initialStore;
37+
return STORE_LOCATION[getStyleStoreSymbol()];
2838
}
2939

3040
function subscribe(listener: () => void) {
3141
const listeners = getListeners();
32-
globalThis[STORE_SYMBOL_LISTENERS] = [...listeners, listener];
42+
STORE_LOCATION[getStyleStoreListenersSymbol()] = [...listeners, listener];
3343
return () => {
34-
globalThis[STORE_SYMBOL_LISTENERS] = listeners.filter((l) => l !== listener);
44+
STORE_LOCATION[getStyleStoreListenersSymbol()] = listeners.filter((l) => l !== listener);
3545
};
3646
}
3747

@@ -43,7 +53,7 @@ export const StyleStore = {
4353
},
4454
setStaticCssInjected: (staticCssInjected: boolean) => {
4555
const curr = getSnapshot();
46-
globalThis[STORE_SYMBOL] = {
56+
STORE_LOCATION[getStyleStoreSymbol()] = {
4757
...curr,
4858
staticCssInjected
4959
};

0 commit comments

Comments
 (0)