Skip to content

fix: ensure availability of internal CSS vars #6393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/base/src/hooks/useStylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
import { StyleStore } from '../stores/StyleStore.js';
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';

export function useStylesheet(styles: StyleDataCSP, componentName: string) {
interface UseStyleSheetOptions {
alwaysInject?: boolean;
}

export function useStylesheet(styles: StyleDataCSP, componentName: string, options?: UseStyleSheetOptions) {
const { staticCssInjected, componentsMap } = useSyncExternalStore(
StyleStore.subscribe,
StyleStore.getSnapshot,
StyleStore.getServerSnapshot
);

useIsomorphicLayoutEffect(() => {
const shouldInject = !staticCssInjected;
const shouldInject = options?.alwaysInject || !staticCssInjected;
if (shouldInject) {
createOrUpdateStyle(styles, 'data-ui5wcr-component', componentName);
StyleStore.mountComponent(componentName);
Expand Down
3 changes: 2 additions & 1 deletion packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"license": "Apache-2.0",
"sideEffects": [
"./dist/Assets.js",
"./dist/json-imports/*"
"./dist/json-imports/*",
"./dist/css/index.css"
],
"scripts": {
"clean": "rimraf dist tmp wrappers",
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/components/ThemeProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let _versionInfoInjected = false;
function ThemeProviderStyles() {
const uniqueId = useId();
useStylesheet(styleData, `${ThemeProvider.displayName}-${uniqueId}`);
useStylesheet(ui5WcVariablesStyleData, `${ThemeProvider.displayName}-css-vars-${uniqueId}`);
useStylesheet(ui5WcVariablesStyleData, `${ThemeProvider.displayName}-css-vars-${uniqueId}`, { alwaysInject: true });
return null;
}

Expand Down
Loading