Service worker cache writes can be cut off; query strings add unread copies

オープン 初心者向け
#150 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript
領域
backend, testing

調査の方向性

sw.jsの95行目付近と116〜119行目を読み、次にtests/unit/service-worker.test.jsを調べて、fetchイベントとキャッシュへの書き込みがどのようにテストされているかを確認してください。既存のテストを確認するため、npm testを実行してください。fetchイベントによってキャッシュへの書き込みが継続され、?utm_source=xを含むリクエストがクエリパラメーターのないURLで保存されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

good first issue reliability severity: low

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.put outside event.waitUntil)
  • sw.js:95 (reads use caches.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 respondWith has 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 of index.html under 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.js checks that the fetch event's waitUntil receives the cache write
  • A request with ?utm_source=x is 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分
マージ済み PR(30日)
4

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TMHSDigital/Static_Chess のほかの issue

TMHSDigital/Static_Chess の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。