Skip to content

Fix theme toggle icon showing wrong state on initial load#264

Merged
ignatz merged 1 commit into
trailbaseio:mainfrom
zyrakq:hotfix/theme-switcher-init-state
Jul 20, 2026
Merged

Fix theme toggle icon showing wrong state on initial load#264
ignatz merged 1 commit into
trailbaseio:mainfrom
zyrakq:hotfix/theme-switcher-init-state

Conversation

@zyrakq

@zyrakq zyrakq commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

createTheme() seeds its signal from currentTheme() before initializeTheme() applies the resolved theme to <html>. The signal is meant to resync via a MutationObserver, but that observer attaches in createTheme()'s own onMount, which fires after the parent App's onMount already toggled the dark class — so the observer misses the mutation and the icon stays stuck on the stale initial state (moon shown on dark startup).

Fix: force setTheme(currentTheme()) right before attaching the observer, resyncing to actual DOM state at mount time regardless of onMount order.

Testing: verified manually with dark preference on load — icon now correct immediately; toggling still works.

Added forced signal resync in createTheme onMount before observer
attaches to lib/theme.ts in vendor/trailbase admin UI
Fixed mismatch where toggle icon showed light-mode state while the
resolved theme on load was already dark

Provide correct initial icon state regardless of onMount race order
Enable icon to reflect actual applied theme immediately on startup
@ignatz

ignatz commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Much appreciated 🙏

@ignatz
ignatz merged commit 0555eb5 into trailbaseio:main Jul 20, 2026
4 of 5 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.

2 participants