Skip to content

Prevent theme flashes during startup - #719

Merged
bgentry merged 1 commit into
masterfrom
bg/prevent-theme-flash
Oct 26, 2026
Merged

bgentry merged 1 commit into
masterfrom
bg/prevent-theme-flash

Conversation

@bgentry

@bgentry bgentry commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Apply the saved light/dark preference or system theme in the HTML head before external styles and JavaScript load. The page currently waits for React and the features API before mounting the theme provider, so a dark page can briefly render with a white background.

Set the initial document color scheme and matching background immediately, using the system preference if browser storage is blocked. The existing theme provider continues to handle theme changes after startup.

The comparison uses cold loads in dark mode with 200 ms network latency, 8 Mbps download throughput, and a 1.2-second features response delay. Both local previews use the same production assets and an empty jobs response.

Before and after theme initialization on a throttled connection

@bgentry
bgentry force-pushed the bg/prevent-theme-flash branch from b774a3a to c058ab0 Compare October 26, 2026 01:19
The initial HTML renders before the theme provider mounts, which waits
for the features request. Dark mode can show a white page while the
styles, JavaScript, and API response load.

Apply the saved or system theme in a synchronous head script and paint
the matching page background before external assets load. Fall back to
the system preference when browser storage is unavailable, and let the
existing theme provider continue managing subsequent changes.
@bgentry
bgentry force-pushed the bg/prevent-theme-flash branch from c058ab0 to 63ea086 Compare October 26, 2026 01:25
@bgentry
bgentry marked this pull request as ready for review October 26, 2026 01:27
@bgentry
bgentry requested a review from brandur October 26, 2026 01:27
@bgentry
bgentry enabled auto-merge (squash) October 26, 2026 01:27
@bgentry
bgentry merged commit 9d4dfb0 into master Oct 26, 2026
22 checks passed
@bgentry
bgentry deleted the bg/prevent-theme-flash branch October 26, 2026 01:31
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.

2 participants