Skip to content

refactor(web): extract useTheme + fixes #129 (App.tsx decomposition, PR 5/7) - #184

Merged
falbany merged 17 commits into
mainfrom
refactor/148-pr5-use-theme
Nov 17, 2026
Merged

falbany merged 17 commits into
mainfrom
refactor/148-pr5-use-theme

Conversation

@falbany

@falbany falbany commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Part of #148 (PR 5/7 of the series in docs/superpowers/specs/2026-11-16-app-tsx-decomposition-design.md). Stacked on #178 → #179 → #182 — shows their commits until those PRs merge.

What

  • New hooks/useTheme.ts: theme state (lazy localStorage restore — validated ∈ {dark, light}, else dark, try/catch), the data-theme attribute effect, applyTheme(next, { persist }) with call-time persistence, and a ref-based toggleTheme({ persist }) for staleness immunity through useGlobalShortcuts's subscription-time capture (theme is not in its re-subscribe dep list).
  • Fixes Web UI: theme preference is persisted but never restored; session-trial theme leaks into localStorage #129, exactly two sanctioned behavior changes:
    1. Stored preference is restored at startup (today every mount starts dark until the config loads).
    2. Session-trial themes no longer leak into localStorage: handleConfigLoaded/handleReloadConfig apply their theme with persist: false. Note this deliberately also covers explicit config loads (LoadConfigModal picker, ConfigEditorModal apply — both route through handleConfigLoaded): the attached config's theme is re-persisted at next startup init.
  • Persistence provenance: config init and both user toggles (Ctrl+Shift+T, StatusBar) persist; everything else doesn't. App's always-persist effect is deleted — the hook is the sole localStorage writer.
  • initializeFromConfig's inline auto→dark ternary replaced by the semantically identical resolveSessionTheme (DRY).

Safety net

  • 7 hook tests (restore, invalid/unreadable fallback, persist both directions, attribute follows, storage-survival on persist:false).
  • 4 App-level pins in the characterization suite — the two new-behavior pins were verified RED before the rewire (mount ignoring stored pref; trial leaking to storage) and the whole-branch reviewer mutation-verified the net: re-injecting the deleted always-persist effect turns the trial pin red.

Test plan

  • cd src/profiles/web && npx vitest run green (354/354)
  • npm run build (tsc) clean
  • Manual: toggle → reload → preference survives; scan a config with a different theme (trial) → stored preference not stolen; fresh session with stored light → light before config load

@falbany
falbany merged commit 453e246 into main Nov 17, 2026
3 checks passed
@falbany
falbany deleted the refactor/148-pr5-use-theme branch November 17, 2026 22:14
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.

Web UI: theme preference is persisted but never restored; session-trial theme leaks into localStorage

1 participant