2
2
3
3
import type { StyleDataCSP } from '@ui5/webcomponents-base/dist/ManagedStyles.js' ;
4
4
import { createOrUpdateStyle , removeStyle } from '@ui5/webcomponents-base/dist/ManagedStyles.js' ;
5
+ import { getCurrentRuntimeIndex } from '@ui5/webcomponents-base/dist/Runtimes.js' ;
5
6
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js' ;
6
7
import { StyleStore } from '../stores/StyleStore.js' ;
7
8
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js' ;
@@ -18,9 +19,10 @@ export function useStylesheet(styles: StyleDataCSP, componentName: string, optio
18
19
) ;
19
20
20
21
useIsomorphicLayoutEffect ( ( ) => {
22
+ const scopedComponentName = `${ componentName } -${ getCurrentRuntimeIndex ( ) } ` ;
21
23
const shouldInject = options ?. alwaysInject || ! staticCssInjected ;
22
24
if ( shouldInject ) {
23
- createOrUpdateStyle ( styles , 'data-ui5wcr-component' , componentName ) ;
25
+ createOrUpdateStyle ( styles , 'data-ui5wcr-component' , scopedComponentName ) ;
24
26
StyleStore . mountComponent ( componentName ) ;
25
27
}
26
28
@@ -29,7 +31,7 @@ export function useStylesheet(styles: StyleDataCSP, componentName: string, optio
29
31
StyleStore . unmountComponent ( componentName ) ;
30
32
const numberOfMountedComponents = componentsMap . get ( componentName ) ! ;
31
33
if ( numberOfMountedComponents <= 0 ) {
32
- removeStyle ( 'data-ui5wcr-component' , componentName ) ;
34
+ removeStyle ( 'data-ui5wcr-component' , scopedComponentName ) ;
33
35
}
34
36
}
35
37
} ;
0 commit comments