22
33import type { StyleDataCSP } from '@ui5/webcomponents-base/dist/ManagedStyles.js' ;
44import { createOrUpdateStyle , removeStyle } from '@ui5/webcomponents-base/dist/ManagedStyles.js' ;
5+ import { getCurrentRuntimeIndex } from '@ui5/webcomponents-base/dist/Runtimes.js' ;
56import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js' ;
67import { StyleStore } from '../stores/StyleStore.js' ;
78import { 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