fix(theme): use Pinia appStore as single theme source for editor - #137
Merged
Conversation
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
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.
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.
appStore(themeType/uiThemeType) — what Settings writes and persists (viapinia-plugin-persistedstate)useThemecomposable (localStorage keysqlkit-theme, default'system') — what the editor chain readEvery call to
useTheme()created a fresh instance (theme = ref('system'),isDark = ref(false)). WhenSQLEditormounted, two composableonMountedhooks fired beforeinitEditor, read the emptysqlkit-themekey, fell back to'system', and re-applied the auto-detected OS theme to<html>— silently removing the.darkclass the store had just set. Monaco then initialized from that auto-detected value.Fix
Make
appStore.uiThemeTypethe single source of truth across the whole app:src/composables/useMonacoEditor.tsappStore.uiThemeTypeinstead ofuseTheme().isDarksrc/components/SQLEditor.vueisDarkderived fromappStore.uiThemeTypeviacomputedsrc/components/markdown-render.vueatom-one-dark/atom-one-light) followsappStore.uiThemeTypevia a swappable<link>src/store/appStore.tsgetEditorTheme()returns valid Monaco theme'vs'instead of'vs-light'src/components/layout/ThemeToggle.vuesqlkit-themekeysrc/composables/useTheme.tssrc/components/README.mdVerification
tsc --noEmitcleangetEditorThemeassertion)