Repository navigation
Apply stored theme on public routes - #15
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Step 6 visual pass found one UX inconsistency worth fixing rather than documenting:
a stored Light preference was ignored on
/and/auth.Cause
The entire theme implementation lived inside
ThemeToggle, which is mounted only byAppLayout—the authenticated shell. So the public routes had nothing applying a theme and always rendered dark.
Worse, even in the app the class was applied in a
useEffectafter mount, so a Light user got aframe of Aurora first.
Fix — centralised initialisation, one system
instead of
src/lib/theme.tsnow owns the theme values, the storage key, the cycle order, normalisation andthe DOM write.
main.tsxcallsinitTheme()at module scope, beforecreateRoot, so the correcttheme is present at first paint on every route.
ThemeToggleimports the same helpers and now onlyreflects the current theme and cycles it.
Deliberately not done: no inline duplicate of this logic in
index.html. The usual no-flash trickis a blocking inline script, but that would be a second implementation of the same normalisation free
to drift. Booting before render is enough here, because the app is fully client-rendered —
#rootisempty in the HTML, so there is no themed paint before the bundle runs. The flash this removes is the
post-mount one that already existed in the authenticated shell.
Behaviour deliberately unchanged
"starry" | "light"; the key is stillathenaeum-theme.aria-label/titlestrings unchanged."academia"still normalises to"starry"and is rewritten, and a staletheme-academiaclass is still cleared from the DOM.prefers-reduced-motionis untouched — the theme never consultsmatchMedia; that staysAuroraBackground's job. There is a test asserting exactly that separation.try/catch. A throw here would happen before render and take thewhole app down, which is a worse failure than a default theme.
Verified in a real browser, not just jsdom
<html>class/lighttheme-lightrgb(248, 250, 252)/authlighttheme-lightrgb(248, 250, 252)/starryrgb(5, 7, 10)/authstarryrgb(5, 7, 10)/rgb(5, 7, 10)Reviewed by eye as well as measured: the light landing page renders as pale blue/lavender over
white with navy text and blue CTAs, and the auth screen as a white card on the same field. The Aurora
layer adapts rather than inverting, so this is a real light theme and not a token swap.
Tests — 17 new, plus 3 repointed
themeApplication.test.tsx(16) exercises behaviour rather than source text, which is what let thedefect through: two-mode recognition, academia migration and write-back, valid values left alone,
nothing written when nothing was stored, Light applied on
/and/auth, applied with nocomponent mounted at all, stale
theme-academiacleared, boot surviving blocked storage,idempotent application, switching back to Aurora, and the motion-preference separation.
Three assertions in
themeTypography.test.tswere readingThemeToggle's source for strings thatnow live in
src/lib/theme.ts. They follow the definitions, and I added a fourth asserting there isexactly one definition — the toggle must not redeclare the key, the order or a
classListwrite, andboot must go through the shared module with
initTheme()beforecreateRoot. That last check neededmatching the calls rather than the identifiers, since both names also appear in the imports.
PROOF.frontendupdated 357 → 374 against actual runs.