Skip to content

fix(theme): sync theme selection across browser windows#3119

Open
leno23 wants to merge 1 commit into
rust-lang:masterfrom
leno23:fix/theme-sync-multi-window-2618
Open

fix(theme): sync theme selection across browser windows#3119
leno23 wants to merge 1 commit into
rust-lang:masterfrom
leno23:fix/theme-sync-multi-window-2618

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 17, 2026

Summary

  • Listen for storage events on mdbook-theme and apply changes in other tabs/windows
  • Clear all known theme classes from <html> before adding the new one (not only previousTheme)

Motivation

With multiple mdBook tabs open, changing the theme in one window left others stale; stacked theme classes could also break rendering (#2618).

Test plan

  • cargo test --test testsuite
  • Manual: open two tabs, switch theme in tab A, confirm tab B updates; switch theme in tab B

Fixes #2618

Made with Cursor

Listen for localStorage `storage` events so other windows/tabs apply
theme changes. When applying a theme, remove every known theme class
from <html> instead of only the previous one, avoiding multiple
theme classes stacking after cross-window updates.

Fixes rust-lang#2618

Co-authored-by: Cursor <cursoragent@cursor.com>
@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Theme selection breaks when switching themes in multiple windows

2 participants