mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
aux window - fix CSS cloning (#196788)
* aux window - fix CSS cloning
* 💄
This commit is contained in:
@@ -798,12 +798,11 @@ export function createStyleSheet(container: HTMLElement = document.head, beforeA
|
||||
continue; // main window is already tracked
|
||||
}
|
||||
|
||||
const clone = cloneGlobalStyleSheet(style, targetWindow);
|
||||
clonedGlobalStylesheets.add(clone);
|
||||
const disposable = cloneGlobalStyleSheet(style, targetWindow);
|
||||
|
||||
event.Event.once(onDidUnregisterWindow)(unregisteredWindow => {
|
||||
if (unregisteredWindow === targetWindow) {
|
||||
clonedGlobalStylesheets.delete(clone);
|
||||
disposable.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -819,17 +818,14 @@ export function isGlobalStylesheet(node: Node): boolean {
|
||||
export function cloneGlobalStylesheets(targetWindow: Window & typeof globalThis): IDisposable {
|
||||
const disposables = new DisposableStore();
|
||||
|
||||
for (const [globalStylesheet, clonedGlobalStylesheets] of globalStylesheets) {
|
||||
const clone = cloneGlobalStyleSheet(globalStylesheet, targetWindow);
|
||||
|
||||
clonedGlobalStylesheets.add(clone);
|
||||
disposables.add(toDisposable(() => clonedGlobalStylesheets.delete(clone)));
|
||||
for (const [globalStylesheet] of globalStylesheets) {
|
||||
disposables.add(cloneGlobalStyleSheet(globalStylesheet, targetWindow));
|
||||
}
|
||||
|
||||
return disposables;
|
||||
}
|
||||
|
||||
function cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, targetWindow: Window & typeof globalThis): HTMLStyleElement {
|
||||
function cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, targetWindow: Window & typeof globalThis): IDisposable {
|
||||
const clone = globalStylesheet.cloneNode(true) as HTMLStyleElement;
|
||||
targetWindow.document.head.appendChild(clone);
|
||||
|
||||
@@ -837,7 +833,19 @@ function cloneGlobalStyleSheet(globalStylesheet: HTMLStyleElement, targetWindow:
|
||||
clone.sheet?.insertRule(rule.cssText, clone.sheet?.cssRules.length);
|
||||
}
|
||||
|
||||
return clone;
|
||||
const observer = new MutationObserver(() => {
|
||||
clone.textContent = globalStylesheet.textContent;
|
||||
});
|
||||
observer.observe(globalStylesheet, { childList: true });
|
||||
|
||||
globalStylesheets.get(globalStylesheet)?.add(clone);
|
||||
|
||||
return toDisposable(() => {
|
||||
observer.disconnect();
|
||||
targetWindow.document.head.removeChild(clone);
|
||||
|
||||
globalStylesheets.get(globalStylesheet)?.delete(clone);
|
||||
});
|
||||
}
|
||||
|
||||
export function createMetaElement(container: HTMLElement = document.head): HTMLMetaElement {
|
||||
|
||||
Reference in New Issue
Block a user