Skip to content

[P1/bug] useTheme doesn't apply theme when Monaco mounts after the change #351

Closed

Description

@EVWorth

Context

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.

Needs human verify

yes

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/theming
    on Jul 31, 2026
  2. EVWorth commented on Sep 11, 2026

    @EVWorth
    OwnerAuthor

    Rejecting this one: the premise does not hold.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/themingauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions