fix(electron): eliminate theme flash on reload and use nativeTheme as source of truth - #1803
Conversation
… backgroundColor and FOUC script
|
@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
index.html, mirroringThemeProvider's own resolution logic, so reloads no longer flash the wrong theme.BrowserWindow'sbackgroundColorfromnativeThemeat creation time to avoid a white flash while the window reloads.theme-prefs.json, following the same atomic-write pattern already used bywindow-state.ts.theme:set/theme:get-system/theme:system-changedIPC channels so the main and renderer processes stay in sync on the current theme.nativeTheme(via preload) instead ofmatchMedia, keepingmatchMediaonly as a fallback for non-Electron environments like tests.Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist
High-level PR Summary
This PR fixes theme flashing issues on Electron app reload by making
nativeThemethe single source of truth for system theme detection. It introduces a blocking inline script inindex.htmlthat applies the correct theme before first paint, persists theme preferences totheme-prefs.jsonusing atomic writes, and synchronizes theme state between main and renderer processes via new IPC channels (theme:set,theme:get-system,theme:system-changed). TheBrowserWindowbackground color now matches the current theme to prevent white flashes during reload.⏱️ Estimated Review Time: 15-30 minutes
💡 Review Order Suggestion
surfsense_local/frontend/src/lib/api.tssurfsense_local/electron/src/main/theme-prefs.tssurfsense_local/electron/src/preload/index.tssurfsense_local/frontend/index.htmlsurfsense_local/frontend/src/components/theme-provider.tsxsurfsense_local/electron/src/main/index.tssurfsense_local/frontend/src/features/onboarding/onboarding-page.tsxsurfsense_local/frontend/src/features/onboarding/onboarding-page.tsx