From 314662b29b7a6d0d95f25d720975bad4558987d4 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 16 Sep 2022 00:39:17 -0400 Subject: [PATCH] Avoids unnecessary callback on first load --- src/webviews/apps/shared/theme.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/webviews/apps/shared/theme.ts b/src/webviews/apps/shared/theme.ts index 1371baf..9dfe8ce 100644 --- a/src/webviews/apps/shared/theme.ts +++ b/src/webviews/apps/shared/theme.ts @@ -2,7 +2,7 @@ import { darken, lighten, opacity } from './colors'; export function initializeAndWatchThemeColors(callback?: () => void) { - const onColorThemeChanged = () => { + const onColorThemeChanged = (mutations?: MutationRecord[]) => { const body = document.body; const computedStyle = window.getComputedStyle(body); @@ -133,13 +133,14 @@ export function initializeAndWatchThemeColors(callback?: () => void) { bodyStyle.setProperty('--color-alert-neutralBorder', 'var(--vscode-input-foreground)'); bodyStyle.setProperty('--color-alert-foreground', 'var(--vscode-input-foreground)'); - callback?.(); + if (mutations != null) { + callback?.(); + } }; - const observer = new MutationObserver(onColorThemeChanged); - - observer.observe(document.body, { attributes: true, attributeFilter: ['class'] }); - onColorThemeChanged(); + + const observer = new MutationObserver(onColorThemeChanged); + observer.observe(document.body, { attributeFilter: ['class'] }); return observer; }