Skip to content

fix(editor): stop Monaco theme leaking across editor instances#282

Merged
debba merged 1 commit into
mainfrom
fix/monaco-global-theme-leak
Jun 4, 2026
Merged

fix(editor): stop Monaco theme leaking across editor instances#282
debba merged 1 commit into
mainfrom
fix/monaco-global-theme-leak

Conversation

@debba
Copy link
Copy Markdown
Collaborator

@debba debba commented Jun 3, 2026

Closes #281

Monaco themes are global to the page, so every editor instance has to agree on which theme is active. Until now each Monaco-based component resolved the theme on its own: most used the UI theme, the SQL editor and the save-query modal honored the editorTheme settings override, and the AI explain modal passed a theme id without ever registering it through loadMonacoTheme. Whichever editor mounted last won, so opening the AI explanation modal re-colored every other editor in the app.

Changes

  • New useEditorTheme hook that resolves the effective editor theme: the editorTheme settings override when set, otherwise the current UI theme (with fallback if the override points to a deleted theme)
  • All Monaco usages now go through the hook: SqlEditorWrapper, SqlPreview, QueryModal, AiExplainModal, AiApprovalModal, ConfigJsonModal, McpModal, McpPage, VisualExplainView, CellCodeEditor, CellDiffEditor
  • AiExplainModal now registers the theme in beforeMount and reacts to theme changes while open, like the other editors already did
  • CellCodeEditor/CellDiffEditor dropped their optional ThemeContext handling (they always render inside the providers); tests updated accordingly
  • Unit tests for the new hook in tests/hooks/useEditorTheme.test.ts

Testing

  • npx tsc --noEmit clean
  • npx vitest run: 2494 passed, 0 failed
  • ESLint clean on the touched files

Monaco themes are global, so any editor that resolved its theme
differently from the others would re-color every editor in the app.
The AI explain modal was the worst offender: it passed a theme id
that was never registered via loadMonacoTheme, and it used the UI
theme instead of the dedicated editor theme override.

Add a useEditorTheme hook that resolves the effective editor theme
(settings override with fallback to the current UI theme) and use it
in every Monaco-based component. The AI explain modal now also
registers the theme in beforeMount like the rest of the editors.

Closes #281
render(<CellCodeEditor value="" onChange={vi.fn()} />, {
wrapper: withTheme(makeTheme("tabularis-dark")),
});
it("follows the editor theme when it changes", () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Test name claims reactivity but only asserts initial render value

The test title says "follows the editor theme when it changes", but the implementation never triggers a re-render after changing mockEditorTheme.current. It only verifies the initial theme passed to useEditorTheme. To actually test reactivity, render the component, update the mock, call rerender(), and then assert the new theme.

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot Bot commented Jun 3, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Fix test or merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
tests/components/ui/CellCodeEditor.test.tsx 90 Test title claims reactivity but only asserts initial render value
Files Reviewed (17 files)
  • src/hooks/useEditorTheme.ts — clean central hook with fallback logic
  • src/components/explain/VisualExplainView.tsx — migrated to useEditorTheme
  • src/components/modals/AiApprovalModal.tsx — migrated to useEditorTheme
  • src/components/modals/AiExplainModal.tsx — migrated + added beforeMount and live theme update
  • src/components/modals/ConfigJsonModal.tsx — migrated to useEditorTheme
  • src/components/modals/McpModal.tsx — migrated to useEditorTheme
  • src/components/modals/QueryModal.tsx — migrated to useEditorTheme
  • src/components/ui/CellCodeEditor.tsx — migrated to useEditorTheme, dropped optional context handling
  • src/components/ui/CellDiffEditor.tsx — migrated to useEditorTheme, dropped optional context handling
  • src/components/ui/SqlEditorWrapper.tsx — migrated to useEditorTheme
  • src/components/ui/SqlPreview.tsx — migrated to useEditorTheme
  • src/pages/McpPage.tsx — migrated to useEditorTheme
  • tests/hooks/useEditorTheme.test.ts — new unit tests for the hook (4 cases)
  • tests/components/ui/CellCodeEditor.test.tsx — updated mocks, 1 misleading test
  • tests/components/ui/SqlPreview.test.tsx — updated mock to useEditorTheme

Fix these issues in Kilo Cloud


Reviewed by kimi-k2.6-20260420 · 332,845 tokens

@debba debba merged commit f7bbef7 into main Jun 4, 2026
2 checks passed
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.

[Bug]: Opening the AI query explanation modal changes syntax colors in every Monaco editor

1 participant