Service worker cache writes can be cut off; query strings add unread copies
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript
调研方向
阅读第 95 行附近以及第 116 至 119 行的 sw.js,然后检查 tests/unit/service-worker.test.js,了解如何测试 fetch 事件和缓存写入。运行 npm test 检查现有测试。完成标准是 fetch 事件能让缓存写入继续执行,并且带有 ?utm_source=x 的请求按不带查询参数的 URL 存储。
由索引模型根据 Issue 内容生成。
描述
Summary
The service worker's fetch handler saves fresh responses to the cache without event.waitUntil, so the browser can stop the worker before the write finishes. It also stores each URL under its full query string, while reads ignore the query string, so every distinct query adds a copy that is never read.
Where
sw.js:116-119(cache.putoutsideevent.waitUntil)sw.js:95(reads usecaches.match(request, { ignoreSearch: true }))
Details
const copy = response.clone();
caches.open(CACHE_NAME).then((cache) => cache.put(request, copy)); // not in event.waitUntil
- The write promise is not kept alive. The browser may terminate the worker once
respondWithhas settled, so the "next visit gets the new version" comment does not always hold. The offline copy can stay a release behind, file by file. - Every distinct query string (shared links with
?utm_...,?source=pwa) stores another copy ofindex.htmlunder its own key. Reads never use those keys, and they are only removed when the cache name changes.
Impact
The offline copy can be stale or mixed after an update, and storage grows slowly with shared links. This is low severity, because the network-first path still serves fresh files while online.
Suggested fix
- Wrap the write:
event.waitUntil(caches.open(CACHE_NAME).then((c) => c.put(key, copy))). - Store under the URL without its query string (
const url = new URL(request.url); url.search = '';), matching how reads look it up.
Acceptance criteria
-
tests/unit/service-worker.test.jschecks that the fetch event'swaitUntilreceives the cache write - A request with
?utm_source=xis stored under the bare URL
Getting started
- Relevant files:
sw.js,tests/unit/service-worker.test.js - How to run tests:
npm ci && npm test
Filed by repo-audit/full-audit at 73cd279. Severity: low. Effort: S. audit-key: reliability|sw.js|fetch
- 主要语言
- JavaScript
- 星标
- 4
- 派生
- 2
- 平均合并
- 6 小时 13 分钟
- 30 天内合并 PR
- 4
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TMHSDigital/Static_Chess 的其他 Issue
-
enhancement good first issue severity: low
难度 2/5 1-3 小时 新手友好度 78/100
TMHSDigital/Static_Chess#163 ·
维护者通常 1 天内回复
-
good first issue performance severity: low
难度 2/5 1-3 小时 新手友好度 86/100
TMHSDigital/Static_Chess#157 ·
维护者通常 1 天内回复
-
documentation good first issue severity: low
难度 1/5 1-3 小时 新手友好度 90/100
TMHSDigital/Static_Chess#155 ·
维护者通常 1 天内回复
-
bug good first issue severity: low
难度 2/5 1-3 小时 新手友好度 84/100
TMHSDigital/Static_Chess#148 ·
维护者通常 1 天内回复
-
bug good first issue severity: low
难度 2/5 1-3 小时 新手友好度 90/100
TMHSDigital/Static_Chess#145 ·
维护者通常 1 天内回复
查看 TMHSDigital/Static_Chess 的全部 Issue
相似的 Issue
-
marketing
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
-
[Bug] Account menu (footer ⚙) doesn't dismiss on outside click — stays open and covers the Bot list未关闭
难度 2/5 1-3 小时 新手友好度 82/100
Fei2411/DeepSeek-Bot#1693 ·
-
area-templates triage:bot-seen triage:needs-human
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/aspire#22356 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
HarperFast/skills#153 ·