Skip to content

fix(theme): use Pinia appStore as single theme source for editor - #137

Merged
Blankll merged 1 commit into
masterfrom
fix/editor-theme-single-source
Aug 12, 2026
Merged

fix(theme): use Pinia appStore as single theme source for editor#137
Blankll merged 1 commit into
masterfrom
fix/editor-theme-single-source

Conversation

@Blankll

@Blankll Blankll commented Aug 12, 2026

Copy link
Copy Markdown
Member

Problem

The editor automatically rewrote the user's dark/light mode configuration, so the user's theme choice from Settings was never applied.

Root cause: two competing theme systems.

  • Pinia appStore (themeType/uiThemeType) — what Settings writes and persists (via pinia-plugin-persistedstate)
  • useTheme composable (localStorage key sqlkit-theme, default 'system') — what the editor chain read

Every call to useTheme() created a fresh instance (theme = ref('system'), isDark = ref(false)). When SQLEditor mounted, two composable onMounted hooks fired before initEditor, read the empty sqlkit-theme key, fell back to 'system', and re-applied the auto-detected OS theme to <html> — silently removing the .dark class the store had just set. Monaco then initialized from that auto-detected value.

Fix

Make appStore.uiThemeType the single source of truth across the whole app:

File Change
src/composables/useMonacoEditor.ts Editor theme reads appStore.uiThemeType instead of useTheme().isDark
src/components/SQLEditor.vue isDark derived from appStore.uiThemeType via computed
src/components/markdown-render.vue highlight.js theme (atom-one-dark/atom-one-light) follows appStore.uiThemeType via a swappable <link>
src/store/appStore.ts getEditorTheme() returns valid Monaco theme 'vs' instead of 'vs-light'
src/components/layout/ThemeToggle.vue Deleted — dead code, only writer of the stale sqlkit-theme key
src/composables/useTheme.ts Deleted — second theme system, no remaining references
src/components/README.md Theme docs updated to describe the store-based approach

Verification

  • tsc --noEmit clean
  • eslint clean
  • 519/519 tests pass (updated getEditorTheme assertion)
  • Production build succeeds; both highlight CSS files emitted as separate assets

The Monaco editor and markdown code highlighting read theme from a
separate useTheme composable (localStorage 'sqlkit-theme', default
'system') instead of the appStore. Every editor mount created fresh
composable instances whose onMounted re-applied the auto-detected
system theme, overwriting the user's dark/light choice from Settings.

Unify on appStore.uiThemeType as the single source of truth:
- useMonacoEditor/SQLEditor: derive isDark from appStore.uiThemeType
- markdown-render: load atom-one-light/dark highlight theme by theme
- getEditorTheme(): fix 'vs-light' to valid Monaco theme 'vs'
- remove dead useTheme composable and ThemeToggle component
@Blankll
Blankll merged commit 2e0d5df into master Aug 12, 2026
3 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.

1 participant