From 2eaaeef4a771787a3da778bdca188343e922d5f3 Mon Sep 17 00:00:00 2001 From: Himself65 Date: Mon, 22 May 2023 15:58:13 +0800 Subject: [PATCH] fix: use hook with first render (#2481) --- apps/web/src/providers/theme-provider.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/web/src/providers/theme-provider.tsx b/apps/web/src/providers/theme-provider.tsx index ec67f3da41..dd4770522b 100644 --- a/apps/web/src/providers/theme-provider.tsx +++ b/apps/web/src/providers/theme-provider.tsx @@ -4,18 +4,16 @@ import { memo, useRef } from 'react'; const themes = ['dark', 'light']; -// a workaround to sync theme to electron -let firstRender = true; - const DesktopThemeSync = memo(function DesktopThemeSync() { const { theme } = useTheme(); const lastThemeRef = useRef(theme); - if (lastThemeRef.current !== theme || firstRender) { + const onceRef = useRef(false); + if (lastThemeRef.current !== theme || !onceRef.current) { if (environment.isDesktop && theme) { window.apis?.ui.handleThemeChange(theme as 'dark' | 'light' | 'system'); } lastThemeRef.current = theme; - firstRender = false; + onceRef.current = true; } return null; });