Repository navigation
Description
🇪🇸 Español
Con el tema oscuro activo, al cambiar de idioma desde el selector del header se ve un parpadeo blanco momentáneo: la página destella en claro y enseguida vuelve a oscuro. El tema no se queda en claro (eso es #95), es un flash transitorio.
Comportamiento esperado: cambiar de idioma no debe producir ningún destello; el fondo oscuro debe mantenerse de forma continua.
Causa raíz: la clase dark en <html> se gestiona de forma imperativa, no la posee React:
src/lib/use-theme.ts(useIsDark) re-aplica la clasedarkdentro de unuseEffectcon dependenciapathname, que corre después del paint.- El
<html>lo renderiza el layout (src/app/[lang]/layout.tsx) sindarken suclassName. Al cambiar de locale (cambia el param[lang]), React reconcilia<html>y resetea suclassName, eliminando la clasedarkque el script anti-FOUC/efecto habían añadido → se pinta en blanco → luego eluseEffectvuelve a añadirdark. Ese ciclo es el parpadeo.
Relacionado: #95 (persistencia del tema al cambiar idioma) — misma área, síntoma distinto.
Archivos: src/lib/use-theme.ts, src/app/[lang]/layout.tsx, src/components/layout/Header.tsx
Solución sugerida: hacer que React sea dueño de la clase de tema en vez de mutarla imperativamente: guardar la preferencia en una cookie, leerla en el layout (Server Component) y renderizar <html className={isDark ? "dark" : ""}>. Así la clase es estable entre renders y navegaciones, se elimina el flash y se reduce la dependencia del script imperativo.
🇬🇧 English
With the dark theme active, switching languages from the header selector shows a brief white flash: the page flashes light and immediately returns to dark. The theme does not stay light (that's #95) — this is a transient flash.
Expected behavior: switching language should produce no flash; the dark background should stay continuous.
Root cause: the dark class on <html> is managed imperatively and not owned by React:
src/lib/use-theme.ts(useIsDark) re-applies thedarkclass inside auseEffectkeyed onpathname, which runs after paint.<html>is rendered by the layout (src/app/[lang]/layout.tsx) withoutdarkin itsclassName. On a locale change (the[lang]param changes), React reconciles<html>and resets itsclassName, removing thedarkclass that the no-FOUC script/effect had added → a white paint → then theuseEffectre-addsdark. That cycle is the flash.
Related: #95 (theme persistence on language switch) — same area, different symptom.
Files: src/lib/use-theme.ts, src/app/[lang]/layout.tsx, src/components/layout/Header.tsx
Suggested fix: make React own the theme class instead of mutating it imperatively: store the preference in a cookie, read it in the layout (Server Component), and render <html className={isDark ? "dark" : ""}>. The class then stays stable across renders and navigations, removing the flash and reducing reliance on the imperative script.
Activity
rue-eru commentedon Jun 18, 2026
Hi! Maybe I can try to work on this Issue since the previous one (#60 ) you assign me to got resolved faster 😅
DataDave-Dev commentedon Jun 18, 2026
Hey @rue-eru,
I just assigned you the issue so you can work on it.
rue-eru commentedon Jun 19, 2026
@DataDave-Dev, I wanted to help with this issue, but I can't get the project to run locally. The build fails with a
web-tree-sittererror, and the database (Turso) requires additional setup.I can still implement the fix based on the root cause analysis you provided, but I won't be able to test it. Could you please test the fix on your end if I open a PR?
DataDave-Dev commentedon Jun 20, 2026
@rue-eru Of course yes, open the PR and I will review it without any problem, don't worry.
fix: eliminate white flash on language switch in dark mode (DataDave-…
fix: White flash on language switch in dark mode #101 (#135)