Repository navigation
PWA worker: never answer a navigation with a redirected cache entry - #6076
Merged
Merged
Conversation
When the host serves index.html through a redirect (Cloudflare Pages
answers /app/index.html with 301 -> /app/index/), cache.addAll follows it
and stores a response marked redirected. The worker then answered the
app's navigation with it, which Chrome rejects ("a redirected response was
used for a request whose redirect mode is not follow"), so a JS-port app
such as the website's skin designer failed to load in any browser that had
installed the worker. Copy such a response before returning it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Flutter vs Codename OneNo benchmark results were produced. |
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.
The JavaScript port's service worker (
pwa-worker.js) answers navigations within its scope with the precachedindex.html. If the host servesindex.htmlthrough a redirect,cache.addAllfollows the redirect and stores a response withredirectedset. Cloudflare Pages does this on codenameone.com:/skindesigner-app/index.htmlreturns 301 to/skindesigner-app/index/. A navigation request uses redirect modemanual, so Chrome rejects that response:As a result the skin designer iframe showed Chrome's "page may be temporarily down or moved" error in any browser that had installed the worker. It stayed broken after a force-reload. Browsers without the worker installed loaded the page normally.
Fix: when a cached response has
redirectedset, copy it into a newResponsewith the same body, status and headers before returning it. Every JS-port PWA uses this worker, so the fix covers all of them, not only the skin designer.tests/pwa/service-worker-contract.mjsadds a case that answers a navigation from a redirected cache entry. It fails without the fix and passes with it.Users who already have a broken worker installed pick this up when the deployed app's worker updates.
🤖 Generated with Claude Code