@@ -5,78 +5,19 @@ Subject: [PATCH] fix: update style id attribute when the content changes
55
66so it can be watched in firefox
77---
8- src/vs/base/browser/domStylesheets.ts | 12 +++++++++-
9- .../themes/browser/workbenchThemeService.ts | 23 ++++++++++++-------
10- 2 files changed, 26 insertions(+), 9 deletions(-)
8+ src/vs/base/browser/domStylesheets.ts | 2 +-
9+ 1 file changed, 1 insertion(+), 1 deletion(-)
1110
1211diff --git a/src/vs/base/browser/domStylesheets.ts b/src/vs/base/browser/domStylesheets.ts
13- index bb699646f05..3d935cf440b 100644
12+ index bb699646f05..dd89c88aa54 100644
1413--- a/src/vs/base/browser/domStylesheets.ts
1514+++ b/src/vs/base/browser/domStylesheets.ts
16- @@ -6,6 +6,7 @@
17- import { DisposableStore, toDisposable, IDisposable } from '../common/lifecycle.js';
18- import { autorun, IObservable } from '../common/observable.js';
19- import { createElement, getWindows, isShadowRoot, sharedMutationObserver } from './dom.js';
20- + import { isFirefox } from './browser.js';
21- import { mainWindow } from './window.js';
22-
23- const globalStylesheets = new Map<HTMLStyleElement /* main stylesheet */, Set<HTMLStyleElement /* aux window clones that track the main stylesheet */>>();
24- @@ -111,7 +112,16 @@ function cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesh
15+ @@ -111,7 +111,7 @@ function cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, globalStylesh
2516 clone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);
2617 }
2718
2819- disposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true })(() => {
29- + let observeInit: MutationObserverInit = {
30- + childList: true
31- + };
32- + if (isFirefox) {
33- + // Firefox doesn't support observing style tag contents
34- + // As a workaround, also observe the data-version attribute that is updated when the content is updated
35- + observeInit = { ...observeInit, attributes: true, attributeFilter: ['data-version'] };
36- + }
37- +
38- + disposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, observeInit)(() => {
20+ + disposables.add(sharedMutationObserver.observe(globalStylesheet, disposables, { childList: true, subtree: true, characterData: true })(() => {
3921 clone.textContent = globalStylesheet.textContent;
4022 }));
4123
42- diff --git a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts
43- index a9dc7c145e0..1f1dc89e3a2 100644
44- --- a/src/vs/workbench/services/themes/browser/workbenchThemeService.ts
45- +++ b/src/vs/workbench/services/themes/browser/workbenchThemeService.ts
46- @@ -33,7 +33,7 @@ import { updateColorThemeConfigurationSchemas, updateFileIconThemeConfigurationS
47- import { ProductIconThemeData, DEFAULT_PRODUCT_ICON_THEME_ID } from './productIconThemeData.js';
48- import { registerProductIconThemeSchemas } from '../common/productIconThemeSchema.js';
49- import { ILogService } from '../../../../platform/log/common/log.js';
50- - import { isWeb } from '../../../../base/common/platform.js';
51- + import { isFirefox, isWeb } from '../../../../base/common/platform.js';
52- import { ColorScheme, ThemeTypeSelector } from '../../../../platform/theme/common/theme.js';
53- import { IHostColorSchemeService } from '../common/hostColorSchemeService.js';
54- import { RunOnceScheduler, Sequencer } from '../../../../base/common/async.js';
55- @@ -793,13 +793,20 @@ class ThemeFileWatcher {
56- }
57-
58- function _applyRules(styleSheetContent: string, rulesClassName: string) {
59- - const themeStyles = mainWindow.document.head.querySelectorAll(`.${rulesClassName}`);
60- - if (themeStyles.length === 0) {
61- - const elStyle = createStyleSheet();
62- - elStyle.className = rulesClassName;
63- - elStyle.textContent = styleSheetContent;
64- - } else {
65- - (<HTMLStyleElement>themeStyles[0]).textContent = styleSheetContent;
66- + let themeStyle = mainWindow.document.head.querySelector(`.${rulesClassName}`);
67- + if (!themeStyle) {
68- + themeStyle = createStyleSheet();
69- + themeStyle.className = rulesClassName;
70- + }
71- +
72- + if (themeStyle.textContent !== styleSheetContent) {
73- + themeStyle.textContent = styleSheetContent;
74- +
75- + if (isFirefox) {
76- + // Firefox doesn't support observing style tag contents
77- + // As a workaround, also update the data-version attribute when it changes so it can be observed
78- + themeStyle.setAttribute('data-version', crypto.randomUUID());
79- + }
80- }
81- }
82-
0 commit comments