Skip to content

fix(electron): eliminate theme flash on reload and use nativeTheme as source of truth - #1803

Merged
AnishSarkar22 merged 2 commits into
MODSetter:devfrom
AnishSarkar22:fix/electron-theme-flash
Sep 17, 2026
Merged

AnishSarkar22 merged 2 commits into
MODSetter:devfrom
AnishSarkar22:fix/electron-theme-flash

Conversation

@AnishSarkar22

@AnishSarkar22 AnishSarkar22 commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Applied the theme before first paint using a blocking inline script in index.html, mirroring ThemeProvider's own resolution logic, so reloads no longer flash the wrong theme.
  • Set the BrowserWindow's backgroundColor from nativeTheme at creation time to avoid a white flash while the window reloads.
  • Persisted the theme preference to theme-prefs.json, following the same atomic-write pattern already used by window-state.ts.
  • Added theme:set / theme:get-system / theme:system-changed IPC channels so the main and renderer processes stay in sync on the current theme.
  • Switched system-theme resolution in the renderer to use nativeTheme (via preload) instead of matchMedia, keeping matchMedia only as a fallback for non-Electron environments like tests.

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR fixes theme flashing issues on Electron app reload by making nativeTheme the single source of truth for system theme detection. It introduces a blocking inline script in index.html that applies the correct theme before first paint, persists theme preferences to theme-prefs.json using atomic writes, and synchronizes theme state between main and renderer processes via new IPC channels (theme:set, theme:get-system, theme:system-changed). The BrowserWindow background color now matches the current theme to prevent white flashes during reload.

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_local/frontend/src/lib/api.ts
2 surfsense_local/electron/src/main/theme-prefs.ts
3 surfsense_local/electron/src/preload/index.ts
4 surfsense_local/frontend/index.html
5 surfsense_local/frontend/src/components/theme-provider.tsx
6 surfsense_local/electron/src/main/index.ts
7 surfsense_local/frontend/src/features/onboarding/onboarding-page.tsx
⚠️ Inconsistent Changes Detected
File Path Warning
surfsense_local/frontend/src/features/onboarding/onboarding-page.tsx Unrelated copy change in onboarding text that doesn't relate to theme handling or flash elimination

Need help? Join our Discord

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

@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.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 21fb67b6-ed39-4f4a-ad86-bcddc2f5da0d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AnishSarkar22
AnishSarkar22 merged commit 014b0ec into MODSetter:dev Sep 17, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant