fix(ratewise): 為導覽 case-3 加上有界網路 fallback#426
Merged
s123104 merged 2 commits intoJun 26, 2026
Conversation
- precache 已驅逐時等網路設 8s 上限,避免連線掛住造成無限白屏 - timeout 後以 event.waitUntil 保留 in-flight fetch,成功仍寫入 html-cache - case 1 暖快取與 case 2 precache 命中維持零延遲不變 - 新增 handleNavigationRequest 單元測試覆蓋 case 2 即時與 case 3 逾時 fallback
Contributor
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 508db98770
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
4 tasks
- 將 matchPrecache mock 由 async 改為回傳 Promise.resolve,消除無 await 的 async - 不影響 case-2/case-3 測試行為 測試:vitest run src/__tests__/sw.test.ts 37/37 通過;eslint 該檔 0 錯誤
Contributor
|
✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。
|
a9eae3d
into
chore/ratewise-production-governance
6 of 7 checks passed
This was referenced Jun 26, 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.
背景
PR #411 的 SW 導覽改為 precache-first 後,case 3(html-cache miss 且
matchPrecache('index.html')miss,例如 iOS precache 被驅逐)對fetch是無上限等待。在「已連線但掛住」的網路(TCP 連上、伺服器永不回應,如 captive portal)下,document 請求永不 resolve → 硬重載後無限白屏。離線(fetch throw)已能快速 fallback,純慢速網路也會在 1–3s 內送達 index.html,因此缺口只剩此 hung-network 案例。嚴重度 Low-Medium。變更
apps/ratewise/src/sw.ts— 僅 case 3:NAVIGATION_FETCH_TIMEOUT_MS = 8000Promise.race為網路 fetch 設 8s 上限;逾時改回傳resolveNavigationFallback()event.waitUntil(networkFetch…)保留 in-flight fetch,網路稍後成功仍寫入 html-cache 供下次導覽為何安全(不會重蹈 #411 修掉的假離線)
#411 移除舊 3s timeout,是因為它可能在 precache 仍存在時把 offline.html 誤送給在線用戶。本分支的 timeout 位於 precache 已確認不存在的 case 3,因此 timeout→offline fallback 結構上不可能造成假離線。Case 1(暖快取)與 case 2(precache 命中)完全未動,維持零延遲。
測試
apps/ratewise/src/__tests__/sw.test.ts新增handleNavigationRequest行為測試:NAVIGATION_NETWORK_TIMEOUT_MS全域 timeout,允許新的 case-3-onlyNAVIGATION_FETCH_TIMEOUT_MS驗證
pnpm --filter @app/ratewise typecheck綠vitest run src/__tests__/sw.test.ts37/37 綠patch changeset 已加入(使用者可見:離線/弱網下載入更穩定,不再可能卡白屏)。
🤖 Generated with Claude Code