Repository navigation
Conversation
…iodec) getTheme is a memo: preview, then random, then the custom theme editor's draft (only while custom is on), then the configured theme. Auto switch tracks a prefers-color-scheme signal; the indicator is a memo. Colour conversions move to utils/colors; dead applyPreset deleted; the engine lint ban covers theme/. Behaviour: closing a theme preview keeps unsaved custom theme edits; the indicator follows custom theme renames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical active finding reports that the random theme picker can index themes with custom IDs and then access nextTheme.bg on an undefined value in frontend/src/ts/theme/random.ts (lines 56 and 78), which may cause a runtime crash.
1 open issue
What changed in this PR
Refactors frontend theming by removing the imperative theme controller and replacing it with derived theme state plus a dedicated theme/ module that owns preview/random/indicator behavior and related effects.
Changes:
- Introduce
src/ts/theme/*to centralize theme preview, randomization, indicator derivation, and config-driven side effects. - Rework
states/themeinto derived memos/signals with explicit precedence (preview > random > draft > configured). - Update UI/commandline call sites, lint rules, and tests to align with the new theme API and draft-based custom-theme editing.
| File | Description |
|---|---|
| frontend/src/ts/utils/colors.ts | Adds helpers to convert between custom theme color shapes and the runtime Theme representation. |
| frontend/src/ts/theme/random.ts | Implements random theme selection logic and refreshes the candidate theme list used for randomization. |
| frontend/src/ts/theme/preview.ts | Introduces a debounced theme preview API and a clear-preview helper. |
| frontend/src/ts/theme/indicator.ts | Derives the footer theme indicator (name/favorite) from theme/config state via a memoized accessor. |
| frontend/src/ts/theme/index.ts | Provides the theme module entry point, exporting the API and wiring global effects like cache/preview/random/draft resets and list refresh. |
| frontend/src/ts/states/theme.ts | Refactors theme state into derived memos and signals for configured theme, random theme, preview theme, and custom-theme drafts. |
| frontend/src/ts/states/core.ts | Removes the prior theme-indicator signal from core state now that the indicator is derived elsewhere. |
| frontend/src/ts/controllers/theme-controller.ts | Removes the old imperative theme controller implementation that has been superseded by derived state and theme/ modules. |
| frontend/src/ts/components/pages/test/TestPage.tsx | Updates test page interactions to use the new theme randomization API. |
| frontend/src/ts/components/pages/settings/custom-setting/Theme.tsx | Switches the custom theme editor to draft-based editing and uses the new color conversion utilities. |
| frontend/src/ts/components/modals/CommandlineModal.tsx | Updates commandline modal behavior to clear theme previews via the new theme API. |
| frontend/src/ts/components/layout/footer/ThemeIndicator.tsx | Switches the footer component to consume the derived theme indicator from theme/indicator. |
| frontend/src/ts/commandline/lists/themes.ts | Updates the themes command list to preview themes using the new preview API. |
| frontend/src/ts/commandline/lists/custom-themes-list.ts | Updates the custom-themes command list to preview custom themes through the new preview API. |
| frontend/src/ts/commandline/lists.ts | Routes theme-related command actions (e.g., randomize) through the new theme/ API surface. |
| frontend/.oxlintrc.json | Adjusts frontend lint rules to account for the new theme/ module and enforce import boundaries. |
| frontend/__tests__/theme/index.spec.ts | Adds/updates unit tests covering derived theme precedence, preview debounce behavior, draft semantics, and caching rules. |
| frontend/__tests__/test/words-wrapper-height.spec.ts | Updates test setup/mocks to reference the new theme module instead of the removed controller. |
| frontend/__tests__/input/after-input-words.spec.tsx | Updates test setup/mocks to reference the new theme module instead of the removed controller. |
| frontend/__tests__/controllers/theme-controller.spec.ts | Removes controller-focused tests now that the controller has been deleted and behavior is covered elsewhere. |
| frontend/__tests__/components/pages/test/WordsInput.spec.tsx | Adjusts component tests to mock or import the new theme module entry points. |
| frontend/__tests__/commandline/lists/themes.spec.ts | Updates commandline list tests to align with the new theme preview/random APIs. |
| frontend/__tests__/__harness__/setup-test-page.ts | Updates the test harness wiring/mocks to use the new src/ts/theme entry points. |
Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
Comment on lines
+56
to
+67
| let randomTheme: ThemeIdentifier; | ||
| let nextTheme = null; | ||
| do { | ||
| randomTheme = themesList[randomThemeIndex] as ThemeIdentifier; | ||
| nextTheme = themes[themesList[randomThemeIndex] as ThemeName]; | ||
| randomThemeIndex++; | ||
| if (randomThemeIndex >= themesList.length) { | ||
| Arrays.shuffle(themesList); | ||
| randomThemeIndex = 0; | ||
| } | ||
| } while (!filter(nextTheme.bg)); | ||
|
|
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.

Summary
The theme controller dissolves: the applied theme is derived state, its behaviour lives in
theme/.setCustomThemeDraft,updateCustomThemeDraftColor) instead ofsetTheme/updateThemeColor.theme/, still allowstheme/state.applyPresetdeleted.Intended behaviour changes:
Evidence
#ff0000(unsaved), commandline preview a theme, Esc → bg back to the saved#323437.After: same steps → bg stays
#ff0000, picker shows#ff0000, first-paint cache stays#323437.__tests__/theme/index.spec.ts: existing controller tests kept, plus preview precedence/debounce, draft only while custom, draft survives a cleared preview, draft dropped on save, previews and random themes never cached. Full frontend suite: 1917 passed.Merge Danger
Door: two-way
Pure frontend refactor, revert restores the controller.
Blast Radius: theming
Every
getTheme()consumer (charts, keymap, favicon, theme CSS) now reads a memo. Wrong precedence would show the wrong theme, e.g. random vs preview vs draft.🤖 Generated with Claude Code