Skip to content
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

fix(web-components): fix for setTheme in Firefox #31911

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
davatron5000 marked this conversation as resolved.
Show resolved Hide resolved
"type": "prerelease",
"comment": "fix for setTheme in Firefox",
"packageName": "@fluentui/web-components",
"email": "rupertdavid@microsoft.com",
"dependentChangeType": "patch"
}
9 changes: 4 additions & 5 deletions packages/web-components/src/theme/set-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ export const setTheme = (theme: Theme) => {
themeStyleTextMap.set(theme, `html{${tokenDeclarations.join('')}}`);
}

// Update the CSSStyleSheet with the new theme
themeStyleSheet.replaceSync(themeStyleTextMap.get(theme)!);
marchbox marked this conversation as resolved.
Show resolved Hide resolved

// Adopt the updated CSSStyleSheet if it hasn't been adopted yet
if (!document.adoptedStyleSheets.includes(themeStyleSheet)) {
document.adoptedStyleSheets.push(themeStyleSheet);
} else {
// The very first call to `setTheme()` within a document doesn’t need to
// call `replaceSync()`, because `CSS.registerProperty()` above is
// sufficient to set the tokens.
themeStyleSheet.replaceSync(themeStyleTextMap.get(theme)!);
}
};

Expand Down
Loading