Skip to content

fix(ratewise): 強化壞 SW 使用者連網自我修復積極傳播#505

Merged
s123104 merged 2 commits into
mainfrom
fix/ratewise-sw-aggressive-propagation-2026-06
Jun 28, 2026
Merged

fix(ratewise): 強化壞 SW 使用者連網自我修復積極傳播#505
s123104 merged 2 commits into
mainfrom
fix/ratewise-sw-aggressive-propagation-2026-06

Conversation

@s123104

@s123104 s123104 commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

問題

修復 PWA precache(#502)後,既有使用者仍可能看到 offline.html:他們的裝置仍由舊 SW 控制(舊版 428 筆/34.5MB precache 在弱網安裝失敗 → index.html 從未快取 → 離線導覽 fallback offline.html)。新版需等舊 SW 更新才生效。

既有機制

UpdatePrompt.tsx 已有「online + needRefresh → 自動 updateServiceWorker(true)(含 SKIP_WAITING + controllerchange 重載)」。缺的是:連線恢復時不會立即檢查更新,且無法偵測壞掉的 active SW 主動修復

修法(版本撕裂零風險)

  1. online 事件監聽(UpdatePrompt):連線恢復立即 registration.update(),讓離線看到 offline.html 的使用者一連網就拉新版。
  2. selfHealStaleShellPrecache(swUtils):向 active SW 探詢 CHECK_SHELL_PRECACHE;回報 shell precache 不健康(或舊 SW 無此 handler 逾時)→ registration.update()
  3. sw.ts 新增 CHECK_SHELL_PRECACHE handler,回報 matchPrecache('index.html') 是否存在。

版本撕裂風險評估

本 PR 只呼叫 registration.update()絕不SKIP_WAITINGunregister。新 SW 的實際接管仍走既有安全流程(等新版安裝完成 → SKIP_WAITING → controllerchange → 重載),不會在未重載的舊頁面上切換 SW。離線時所有路徑直接略過(保留離線快取)。

驗證

  • pnpm typecheck 通過
  • swUtils + sw 共 59 測試全綠(新增 4 則 selfHeal + 1 則 handler 斷言)
  • pnpm build:ratewise 成功,precache 92 筆穩定,CHECK_SHELL_PRECACHE 已注入 dist/sw.js

🤖 Generated with Claude Code

- 新增 online 事件監聽:連線恢復立即 registration.update(),加速修復傳播
- selfHealStaleShellPrecache:探詢 active SW shell precache 健康度,不健康即觸發 update()
- sw.ts 新增 CHECK_SHELL_PRECACHE handler 回報 index.html 是否仍在 precache
- 版本撕裂防護:只呼叫 update(),絕不送 SKIP_WAITING/unregister;接管走既有重載流程
- 既有壞 SW 使用者下次連網自動拉取新版,不再卡在 offline.html

測試:typecheck 通過;swUtils+sw 59 測試全綠;build precache 92 筆穩定

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

- 新增 swHealth 模組:探針判斷 index.html 缺失與 legacy precache 膨脹
- 壞 SW 連網時 update + forceServiceWorkerUpdate 整頁重載一次
- 健康 SW 維持 prompt UX,needRefresh 自動接管僅限壞 SW
- 補 swHealth 單元測試與 changeset/002 紀錄

測試:vitest swHealth/swUtils/sw.test.ts、pnpm typecheck、pnpm build:ratewise

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@s123104 s123104 merged commit c5f08b8 into main Jun 28, 2026
17 checks passed
@s123104 s123104 deleted the fix/ratewise-sw-aggressive-propagation-2026-06 branch June 28, 2026 07:15
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