fix(theme): 软导航主题回退——ThemeScript 补 data-astro-rerun

- 病根:ClientRouter 软导航换 html 属性把 data-theme 抹回无主题态,
  而内联脚本默认仅首次执行(Astro 规矩:重跑须显式 data-astro-rerun)
  ——切换明暗后一切栏目即回系统默认(用户实测报告)
- 写入端审计:Header/Keyboard t/命令面板/终端四入口均写同一
  localStorage key,无第二套实现,病灶唯一
- E2E 补软导航持久断言(原仅测 reload,漏了真实 bug 场景)

验证: node tests/e2e.mjs 31/31 PASS(软导航后=dark 断言新增)

Spec: none (线上热修:单属性缺陷 + 回归断言)

Co-authored-by: GLM-5.3
This commit is contained in:
wait4xandGLM-5.3 committed 2026-10-25 20:15:06 +08:00
1 parent a10141dfd8
commit e57c853f20
2 files changed
+11 -3

No files matched your search

+4 -1
View File
@@ -3,7 +3,10 @@
// 优先级:用户手选(localStorage) > 系统偏好;切换按钮(T7 键盘/组件)写同一 key。
---
<script is:inline>
<script is:inline data-astro-rerun>
// data-astro-rerun:ClientRouter 软导航会换 html 属性(data-theme 被新页
// 面的无主题态覆盖),内联脚本默认只跑首次——不加重跑标记,切主题后一导航
// 就回退系统默认(用户实测报告的 bug)
(function () {
var saved = localStorage.getItem('theme');
var theme = saved === 'light' || saved === 'dark'
+7 -2
View File
@@ -39,9 +39,14 @@ const before = await page.getAttribute('html', 'data-theme');
await page.click('[data-theme-toggle]');
const after = await page.getAttribute('html', 'data-theme');
ok('明暗切换·按钮', before !== after, `${before}→${after}`);
await page.reload({ waitUntil: 'networkidle' });
// 持久化双测:软导航(真实 bug 场景:VT 换页曾把主题抹回默认)+ 刷新
await page.click('nav a[href="/gallery/"]');
await page.waitForLoadState('networkidle');
const softNav = await page.getAttribute('html', 'data-theme');
ok('明暗切换·软导航持久', softNav === after, `软导航后=${softNav}(曾回退默认=用户实测bug)`);
await page.goto(BASE + '/', { waitUntil: 'networkidle' });
const persisted = await page.getAttribute('html', 'data-theme');
ok('明暗切换·持久化', persisted === after, `reload=${persisted}`);
ok('明暗切换·刷新持久', persisted === after, `reload=${persisted}`);
await page.keyboard.press('t');
const byKey = await page.getAttribute('html', 'data-theme');
ok('明暗切换·t 键', byKey !== persisted, `t 后=${byKey}`);