Skip to content

Commit 5170959

Browse files
authored
fix(useStyleSheet): scope component name to ui5wc runtime (#6397)
1 parent abd9e7a commit 5170959

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

.github/workflows/release-snapshot.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: 'Release - Snapshot'
22

3-
on:
4-
workflow_dispatch
3+
on: workflow_dispatch
54

65
jobs:
76
test:

packages/base/src/hooks/useStylesheet.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import type { StyleDataCSP } from '@ui5/webcomponents-base/dist/ManagedStyles.js';
44
import { createOrUpdateStyle, removeStyle } from '@ui5/webcomponents-base/dist/ManagedStyles.js';
5+
import { getCurrentRuntimeIndex } from '@ui5/webcomponents-base/dist/Runtimes.js';
56
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
67
import { StyleStore } from '../stores/StyleStore.js';
78
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
@@ -18,9 +19,10 @@ export function useStylesheet(styles: StyleDataCSP, componentName: string, optio
1819
);
1920

2021
useIsomorphicLayoutEffect(() => {
22+
const scopedComponentName = `${componentName}-${getCurrentRuntimeIndex()}`;
2123
const shouldInject = options?.alwaysInject || !staticCssInjected;
2224
if (shouldInject) {
23-
createOrUpdateStyle(styles, 'data-ui5wcr-component', componentName);
25+
createOrUpdateStyle(styles, 'data-ui5wcr-component', scopedComponentName);
2426
StyleStore.mountComponent(componentName);
2527
}
2628

@@ -29,7 +31,7 @@ export function useStylesheet(styles: StyleDataCSP, componentName: string, optio
2931
StyleStore.unmountComponent(componentName);
3032
const numberOfMountedComponents = componentsMap.get(componentName)!;
3133
if (numberOfMountedComponents <= 0) {
32-
removeStyle('data-ui5wcr-component', componentName);
34+
removeStyle('data-ui5wcr-component', scopedComponentName);
3335
}
3436
}
3537
};

0 commit comments

Comments
 (0)