Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(electron): system theme (#2237)

Himself654a50fe584cd0
diff --git a/apps/web/src/providers/ThemeProvider.tsx b/apps/web/src/providers/ThemeProvider.tsx
index ad4f5ae529..c34b401a14 100644
--- a/apps/web/src/providers/ThemeProvider.tsx
+++ b/apps/web/src/providers/ThemeProvider.tsx
@@ -2,17 +2,19 @@ import type { ThemeProviderProps } from '@affine/component';
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes';
import type { PropsWithChildren } from 'react';
import type React from 'react';
-import { memo, useEffect } from 'react';
+import { memo, useRef } from 'react';
const themes = ['dark', 'light'];
const DesktopThemeSync = memo(function DesktopThemeSync() {
- const { resolvedTheme } = useTheme();
- useEffect(() => {
- if (environment.isDesktop) {
- window.apis?.onThemeChange(resolvedTheme === 'dark' ? 'dark' : 'light');
+ const { theme } = useTheme();
+ const lastThemeRef = useRef(theme);
+ if (lastThemeRef.current !== theme) {
+ if (environment.isDesktop && theme) {
+ window.apis?.onThemeChange(theme);
}
- }, [resolvedTheme]);
+ lastThemeRef.current = theme;
+ }
return null;
});