fix: Theme toggle icon resets to System icon on page refresh despite active Dark/Light theme

未关闭 适合新手
#269 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

  • #270 来自 @puneetnith28 —— 已关闭,未合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript
领域
frontend

调研方向

从主题切换触发图标的实现入手,检查 SSR 和 hydration 期间如何使用 currentTheme。添加 issue 中描述的关键行为,然后在刷新页面后验证,持久化的 Dark 和 Light 主题会显示 Moon 和 Sun 图标,而不是 System。

由索引模型根据 Issue 内容生成。

描述

Summary

Fix the theme toggle icon resetting to the System icon after page refresh.

Issue

The selected theme is saved correctly, but after refreshing the page, the toggle still shows the System icon instead of the Sun or Moon icon.

Root Cause

During SSR, the System icon is rendered by default. During Preact hydration, the existing SVG is reused instead of being replaced with the correct theme icon.

Proposed Fix

Add a key={currentTheme} prop to the trigger icon so Preact's reconciler cleanly replaces the stale server-rendered SVG node during client hydration:

<TriggerIcon key={currentTheme} height="20" />
主要语言
JavaScript
星标
22
派生
91
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

webpack/webpack-doc-kit 的其他 Issue

查看 webpack/webpack-doc-kit 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。