Skip to content

Commit 4b964a5

Browse files
committed
Fix color scheme update on theme toggle
1 parent 1c9c155 commit 4b964a5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

no-flash-color-mode-plugin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ export default function noFlashColorModePlugin(context) {
3131
document.documentElement.setAttribute('data-theme', theme);
3232
document.documentElement.setAttribute('data-theme-choice', storedTheme || (respectPrefersColorScheme ? 'system' : defaultMode));
3333
document.documentElement.style.colorScheme = theme;
34+
35+
var observer = new MutationObserver(function(mutationsList) {
36+
for (var i = 0; i < mutationsList.length; i++) {
37+
var mutation = mutationsList[i];
38+
if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') {
39+
var newTheme = document.documentElement.getAttribute('data-theme');
40+
if (newTheme) {
41+
document.documentElement.style.colorScheme = newTheme;
42+
}
43+
}
44+
}
45+
});
46+
47+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] });
3448
})();`,
3549
},
3650
],

0 commit comments

Comments
 (0)