You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P1/bug] useTheme doesn't apply theme when Monaco mounts after the change #351
useTheme.ts:6-12 (useEffect calls monaco.editor.setTheme only when monaco is available).
Problem
The hook explicitly checks if (monaco) and bails if it's null. On initial render, Monaco is loading (it's async). The theme change before Monaco mounts is recorded in the effectiveTheme state but never applied to Monaco. Once Monaco mounts, the editor uses its default theme (vs), not the user's preference. The useTheme.test.ts:42-49 test covers monaco: null (no crash) but doesn't cover the "Monaco mounts after theme change" race.
Files
src/hooks/useTheme.ts:6-12
Expected
Changing the theme before Monaco mounts results in the new theme being applied to the editor when it mounts.
Proposed fix
Scope S — add a useEffect that triggers when monaco becomes non-null (i.e., when Monaco mounts); check the current effectiveTheme and apply it. OR pass the theme via Monaco's theme prop in SQLEditor.tsx initialization, which is the more idiomatic Monaco pattern.
Acceptance
Changing the theme before Monaco mounts results in the new theme being applied to the editor when it mounts.
useTheme lists monaco in its dependency array (useTheme.ts:12), so when Monaco finishes loading and useMonaco() goes from null to an instance, the effect re-runs and applies the current theme. The issue reads the if (monaco) guard as a bail-out that never retries; it is a guard on an effect that retries by construction.
I added the test the issue says is missing — theme set to light while useMonaco() returns null, then Monaco mounts — and it passes against the unmodified hook.
Belt and braces beyond that: SQLEditor also passes theme={...} to the <Editor> (SQLEditor.tsx:308), which is the idiomatic Monaco pattern the issue offers as its alternative fix, and CellViewerModal does the same. Both paths are already in place.
Also removed while here: a test in useTheme.test.ts named "re-runs and updates theme when effectiveTheme changes" that set up two renders and then asserted nothing, ending in a comment about what it would need to do. The test below it already covers that case properly.
Activity
EVWorth commentedon Sep 11, 2026
Rejecting this one: the premise does not hold.
useThemelistsmonacoin its dependency array (useTheme.ts:12), so when Monaco finishes loading anduseMonaco()goes from null to an instance, the effect re-runs and applies the current theme. The issue reads theif (monaco)guard as a bail-out that never retries; it is a guard on an effect that retries by construction.I added the test the issue says is missing — theme set to light while
useMonaco()returns null, then Monaco mounts — and it passes against the unmodified hook.Belt and braces beyond that:
SQLEditoralso passestheme={...}to the<Editor>(SQLEditor.tsx:308), which is the idiomatic Monaco pattern the issue offers as its alternative fix, andCellViewerModaldoes the same. Both paths are already in place.Also removed while here: a test in
useTheme.test.tsnamed "re-runs and updates theme when effectiveTheme changes" that set up two renders and then asserted nothing, ending in a comment about what it would need to do. The test below it already covers that case properly.