Skip to content

面板不再在加载时写死深浅色 - #41

Merged
stqfdyr merged 1 commit into
mainfrom
fix/panel-theme-follows-system
Sep 23, 2026
Merged

stqfdyr merged 1 commit into
mainfrom
fix/panel-theme-follows-system

Conversation

@stqfdyr

@stqfdyr stqfdyr commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

面板在挂载时无条件把系统配色写进 localStorage,把同源公开主题的「跟随系统」一并钉死。

  • 面板与公开主题同源、共用 theme 这个 key。访客点开一次后台(或在公开页关闭时被跳转过去),公开页的 theme 就被填上当时的系统配色,此后不再跟随系统。
  • 改为只有点击切换时才落盘,未落盘时读 prefers-color-scheme。三个 app 必须一致,否则任何一个在加载时写盘都会把其余的钉死。
  • 系统配色改用 useSyncExternalStore 订阅:此前拷进 state,监听器要等 effect 才挂上,落在首次渲染与挂载之间的那次切换没有人听见。

tsc -b、oxlint、npm test、npm run build 通过。两个主题的同一处见 monitor-probe/monitor-theme-serverstatus#5 与 monitor-probe/monitor-theme-default#4。

面板与公开主题同源,共用 theme 这个 key。面板此前在挂载的 effect 里无条件写盘,于是
访客只要点开一次后台(或在公开页关闭时被跳转过去),公开页的 theme 就被填上了当时的
系统配色,此后不再跟随系统——而两个主题都以「没写盘就跟随系统」为约定,这一条必须三个
app 一致。改为只有点击切换时才落盘。

系统配色改用 useSyncExternalStore 订阅:此前拷进 state,监听器要等 effect 才挂上,落在
首次渲染与挂载之间的那次切换没有人听见。

两个主题的同一处见 monitor-probe/monitor-theme-serverstatus#5 与
monitor-probe/monitor-theme-default#4。
@stqfdyr
stqfdyr merged commit 364d351 into main Sep 23, 2026
1 check passed
@stqfdyr
stqfdyr deleted the fix/panel-theme-follows-system branch September 23, 2026 05:07
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