From 4f421efb22a7b9c154b537aca1407207393eb84b Mon Sep 17 00:00:00 2001 From: donteatfriedrice Date: Wed, 15 Jan 2025 04:04:06 +0000 Subject: [PATCH] fix(editor): init default theme observer value according to data-theme (#9698) --- blocksuite/affine/shared/src/services/theme-service.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/blocksuite/affine/shared/src/services/theme-service.ts b/blocksuite/affine/shared/src/services/theme-service.ts index 54dde1d07..ab62a3baf 100644 --- a/blocksuite/affine/shared/src/services/theme-service.ts +++ b/blocksuite/affine/shared/src/services/theme-service.ts @@ -161,10 +161,17 @@ export class ThemeService extends Extension { export class ThemeObserver { private readonly observer: MutationObserver; - theme$ = signal(ColorScheme.Light); + theme$: Signal; constructor() { const COLOR_SCHEMES: string[] = Object.values(ColorScheme); + // Set initial theme according to the data-theme attribute + const initialMode = document.documentElement.dataset.theme; + this.theme$ = signal( + initialMode && COLOR_SCHEMES.includes(initialMode) + ? (initialMode as ColorScheme) + : ColorScheme.Light + ); this.observer = new MutationObserver(() => { const mode = document.documentElement.dataset.theme; if (!mode) return;