From 936c38a21d8901aaf7f29e462083eec9e900d19a Mon Sep 17 00:00:00 2001 From: Dmitry Rubtsov Date: Fri, 3 Jul 2026 13:34:11 +0200 Subject: [PATCH] Fix custom theme not applied on startup (light-theme dividers) (#200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Launching with a custom dark theme left every divider in light-theme colors until you re-toggled the theme in Settings. `applyTheme` was copy-pasted across the components and the copies drifted. Three of them (+page.svelte's onMount block, AppLayout.svelte, NoteWindow.svelte) had no custom-* branch, so for a custom theme they stripped the dark class and data-theme attribute, matched nothing, and fell back to the bare light :root values. `+layout.svelte` applied the custom theme correctly, but `AppLayout` — the always-mounted shell — re-runs its own broken copy from an `$effect` on `$theme`, immediately wiping it out. Dividers gave it away because custom themes override `--border-color` but not `--border-light`, which dividers use. Fix: consolidate into a single `applyTheme`(which already owns darkThemes/isDarkTheme) with a real `custom-*` branch, and have every call site use it and pass the loaded custom themes so `custom-*` ids resolve. Reviewed-on: https://codeberg.org/ArkHost/HelixNotes/pulls/200 --- src/lib/components/AppLayout.svelte | 22 +++------- src/lib/components/CommandPalette.svelte | 14 +------ src/lib/components/NoteWindow.svelte | 17 ++------ src/lib/components/SettingsPanel.svelte | 30 +------------- src/lib/platform.ts | 53 ++++++++++++++++++++++++ src/routes/+layout.svelte | 45 +------------------- src/routes/+page.svelte | 13 +----- 7 files changed, 68 insertions(+), 126 deletions(-) diff --git a/src/lib/components/AppLayout.svelte b/src/lib/components/AppLayout.svelte index 11e3680..3c10d44 100644 --- a/src/lib/components/AppLayout.svelte +++ b/src/lib/components/AppLayout.svelte @@ -21,6 +21,7 @@ showSearch, showCommandPalette, theme, + customThemes, focusMode, readOnly, activeNote, @@ -62,7 +63,7 @@ const isMac = navigator.platform.startsWith('Mac'); const isMobile = $derived($platformIsMobile); import { loadVaultState, saveVaultState, readNote, createDailyNote, createBackup, getPendingOpenFile, addQuickAccess, removeQuickAccess, getQuickAccess, setTheme, syncNow, setTaskDone, setTaskPriority, setTaskDue, findOrphanedAttachments, trashOrphanedAttachments } from '$lib/api'; - import { darkThemes, isAndroid } from '$lib/platform'; + import { applyTheme, isAndroid } from '$lib/platform'; import { debounce } from '$lib/utils/debounce'; import { openNoteWindow } from '$lib/utils/window'; import { get } from 'svelte/store'; @@ -509,21 +510,8 @@ } } - function applyTheme(t: string) { - const namedThemes = ['solarized-light', 'solarized-dark', 'catppuccin', 'nord', 'tokyo-night', 'github-light', 'github-dark', 'dracula', 'blueberry', 'forest-green', 'gruvbox', 'midnight-tide', 'cherry-blossom', 'synthwave', 'ember', 'moonlit', 'light-coffee', 'dark-coffee', 'cotton-candy', 'crimson', 'cloud', 'peach', 'material-dark', 'material-light', 'monokai', 'rose-pine', 'everforest', 'horizon', 'cyberpunk', 'black', 'one-dark']; - const root = document.documentElement; - root.classList.remove('dark'); - root.removeAttribute('data-theme'); - if (namedThemes.includes(t)) { - root.setAttribute('data-theme', t); - if (darkThemes.includes(t)) root.classList.add('dark'); - } else if (t === 'dark' || (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) { - root.classList.add('dark'); - } - } - $effect(() => { - applyTheme($theme); + applyTheme($theme, $customThemes); }); $effect(() => { @@ -605,10 +593,10 @@ prefetchPromise = readNote(lastNotePath).catch(() => null); } - applyTheme($theme); + applyTheme($theme, $customThemes); window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { - if ($theme === 'system') applyTheme('system'); + if ($theme === 'system') applyTheme('system', $customThemes); }); // Run sidebar and note list refresh in parallel diff --git a/src/lib/components/CommandPalette.svelte b/src/lib/components/CommandPalette.svelte index 75289bf..a35545c 100644 --- a/src/lib/components/CommandPalette.svelte +++ b/src/lib/components/CommandPalette.svelte @@ -1,7 +1,7 @@ {#if $showCommandPalette} diff --git a/src/lib/components/NoteWindow.svelte b/src/lib/components/NoteWindow.svelte index 4634cee..95a15b0 100644 --- a/src/lib/components/NoteWindow.svelte +++ b/src/lib/components/NoteWindow.svelte @@ -9,7 +9,8 @@ editorDirty, readOnly, sourceMode, - theme + theme, + customThemes } from '$lib/stores/app'; import { readNote } from '$lib/api'; import { keybindings, matchAction } from '$lib/keybindings'; @@ -17,7 +18,7 @@ let { notePath }: { notePath: string } = $props(); - import { darkThemes } from '$lib/platform'; + import { applyTheme } from '$lib/platform'; const appWindow = getCurrentWindow(); const isMac = navigator.platform.startsWith('Mac'); @@ -37,17 +38,7 @@ }); $effect(() => { - const t = $theme || 'system'; - const namedThemes = ['solarized-light', 'solarized-dark', 'catppuccin', 'nord', 'tokyo-night', 'github-light', 'github-dark', 'dracula', 'blueberry', 'forest-green', 'gruvbox', 'midnight-tide', 'cherry-blossom', 'synthwave', 'ember', 'moonlit', 'light-coffee', 'dark-coffee', 'cotton-candy', 'crimson', 'cloud', 'peach', 'material-dark', 'material-light', 'monokai', 'rose-pine', 'everforest', 'horizon', 'cyberpunk', 'black', 'one-dark']; - const root = document.documentElement; - root.classList.remove('dark'); - root.removeAttribute('data-theme'); - if (namedThemes.includes(t)) { - root.setAttribute('data-theme', t); - if (darkThemes.includes(t)) root.classList.add('dark'); - } else if (t === 'dark' || (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) { - root.classList.add('dark'); - } + applyTheme($theme || 'system', $customThemes); }); let lastMouseDown = 0; diff --git a/src/lib/components/SettingsPanel.svelte b/src/lib/components/SettingsPanel.svelte index e6860b5..0689941 100644 --- a/src/lib/components/SettingsPanel.svelte +++ b/src/lib/components/SettingsPanel.svelte @@ -1,7 +1,7 @@