fix(ratewise): 強化壞 SW 使用者連網自我修復積極傳播#505
Merged
Merged
Conversation
- 新增 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>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
- 新增 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>
Contributor
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
This was referenced Jun 28, 2026
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.
問題
修復 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 主動修復。修法(版本撕裂零風險)
registration.update(),讓離線看到 offline.html 的使用者一連網就拉新版。CHECK_SHELL_PRECACHE;回報 shell precache 不健康(或舊 SW 無此 handler 逾時)→registration.update()。CHECK_SHELL_PRECACHEhandler,回報matchPrecache('index.html')是否存在。版本撕裂風險評估
本 PR 只呼叫
registration.update(),絕不送SKIP_WAITING或unregister。新 SW 的實際接管仍走既有安全流程(等新版安裝完成 → SKIP_WAITING → controllerchange → 重載),不會在未重載的舊頁面上切換 SW。離線時所有路徑直接略過(保留離線快取)。驗證
pnpm typecheck通過pnpm build:ratewise成功,precache 92 筆穩定,CHECK_SHELL_PRECACHE已注入 dist/sw.js🤖 Generated with Claude Code