Skip to content
SprecherEast
Issue 421

bug: A dark-mode visit can paint light before the theme script runs

Back to our plan
Open
bugfrontendstylingpriority: low

Type

bug

Summary

A page can paint in the light theme before InitTheme sets a dark one.

Problem

Found while working on #413. InitTheme uses next/script with strategy="beforeInteractive". In the App Router that becomes a self.__next_s.push(…) entry, which Next runs once its own scripts load, not as the browser reads the page. Under next dev, data-theme on <html> was still unset at DOMContentLoaded on /about with the site set to dark. Rendering a plain inline <script> in the layout's <head> instead set it by then.

That plain script makes React 19 log "Encountered a script tag while rendering React component" in the browser in development. That's why #413 didn't take it. A production build hasn't been checked.

Proposed fix

Check a production build for a flash of the light theme on a dark-mode visit. If there is one, take this up with #370 step 3 (replace the template's ThemeProvider with next-themes, which injects its script before first paint), rather than hand-rolling it.

Acceptance criteria

  • Not done: With the site on dark, no page paints light first in a production build (checked by reading data-theme at DOMContentLoaded, and visually on a throttled connection).

Area

frontend

Priority

priority: low


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab