Repository navigation
深浅色实时跟随系统 - #4
Merged
Merged
Conversation
此前在首次访问就把系统偏好写进 localStorage,此后系统再切换不再跟随,等于把「跟随系统」 变成一次性快照。改为只有点击切换时才落盘,未落盘时实时跟随 prefers-color-scheme。
此前把 DARK_MEDIA.matches 拷进 state,监听器要等 effect 才挂上:落在首次渲染与挂载之间 的那次切换没有人听见,而按日夜计划切换的下一次在几小时之后。改用 useSyncExternalStore 直接订阅。面板在同源的 /admin/ 下共用 theme 这个 key,任何一个 app 在加载时写盘都会把 其余的钉死,这条约束写进了注释。
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.
深浅色此前只在首次访问跟随系统一次,之后不再跟随。
localStorage,于是「跟随系统」变成一次性快照:访客此后换了系统配色,页面纹丝不动。prefers-color-scheme并监听它的 change。tsc -b、oxlint、npm test、npm run build通过;浏览器实测:未点过切换时随系统实时变化,点过之后固定。同一处代码在 monitor-probe/monitor-theme-serverstatus#5 一并修了。