Skip to content

PWA worker: never answer a navigation with a redirected cache entry - #6076

Merged
shai-almog merged 1 commit into
masterfrom
pwa-worker-redirected-shell
Oct 22, 2026
Merged

shai-almog merged 1 commit into
masterfrom
pwa-worker-redirected-shell

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

The JavaScript port's service worker (pwa-worker.js) answers navigations within its scope with the precached index.html. If the host serves index.html through a redirect, cache.addAll follows the redirect and stores a response with redirected set. Cloudflare Pages does this on codenameone.com: /skindesigner-app/index.html returns 301 to /skindesigner-app/index/. A navigation request uses redirect mode manual, so Chrome rejects that response:

The FetchEvent for "https://www.codenameone.com/skindesigner-app/?theme=light" resulted in a network error response: a redirected response was used for a request whose redirect mode is not "follow".

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 redirected set, copy it into a new Response with 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.mjs adds 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

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>
@shai-almog
shai-almog merged commit 990a50e into master Oct 22, 2026
9 of 36 checks passed
@shai-almog
shai-almog deleted the pwa-worker-redirected-shell branch October 22, 2026 12:51
@github-actions

Copy link
Copy Markdown
Contributor

Flutter vs Codename One

No benchmark results were produced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant