From 308249abdb2ab04d5f36bc77d05585278151bc23 Mon Sep 17 00:00:00 2001 From: weishu Date: Thu, 29 Jan 2026 16:33:30 +0800 Subject: [PATCH] fix(web): improve font scale compatibility and defaults --- web/src/hooks/useFontScale.ts | 4 +++- web/src/index.css | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/web/src/hooks/useFontScale.ts b/web/src/hooks/useFontScale.ts index fc0b426a..b4b038bc 100644 --- a/web/src/hooks/useFontScale.ts +++ b/web/src/hooks/useFontScale.ts @@ -20,6 +20,8 @@ function isBrowser(): boolean { return typeof window !== 'undefined' && typeof document !== 'undefined' } +const useIsomorphicLayoutEffect = isBrowser() ? useLayoutEffect : useEffect + function safeGetItem(key: string): string | null { if (!isBrowser()) { return null @@ -79,7 +81,7 @@ export function initializeFontScale(): void { export function useFontScale(): { fontScale: FontScale; setFontScale: (scale: FontScale) => void } { const [fontScale, setFontScaleState] = useState(getInitialFontScale) - useLayoutEffect(() => { + useIsomorphicLayoutEffect(() => { applyFontScale(fontScale) }, [fontScale]) diff --git a/web/src/index.css b/web/src/index.css index c0c952c2..f2e1057c 100644 --- a/web/src/index.css +++ b/web/src/index.css @@ -90,7 +90,7 @@ } html { - font-size: calc(100% * var(--app-font-scale)); + font-size: calc(100% * var(--app-font-scale, 1)); } html, @@ -105,6 +105,7 @@ body { } body { + font-size: 1rem; background: var(--app-bg); color: var(--app-fg); }