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

Offen Anfängerfreundlich
#150 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
88/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript
Bereich
backend, testing

Rechercherichtung

Lies sw.js um Zeile 95 und die Zeilen 116–119 und sieh dir dann tests/unit/service-worker.test.js an, um zu sehen, wie Fetch-Ereignisse und Cache-Schreibvorgänge getestet werden. Führe npm test aus, um die bestehenden Tests zu prüfen. Fertig ist die Aufgabe, wenn das Fetch-Ereignis den Cache-Schreibvorgang am Leben hält und eine Anfrage mit ?utm_source=x unter ihrer URL ohne Query-Parameter gespeichert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
JavaScript
Sterne
4
Forks
2
Ø Merge
6 Std. 13 Min.
Gemergte PRs (30 T.)
4

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TMHSDigital/Static_Chess

Alle Issues in TMHSDigital/Static_Chess

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.