Skip to content

fix(pwa): narrow scope to /wp-admin/ and throttle SW reloads#181

Merged
epeicher merged 1 commit into
trunkfrom
fix/pwa-link-capture-and-sw-reload-loop
May 12, 2026
Merged

fix(pwa): narrow scope to /wp-admin/ and throttle SW reloads#181
epeicher merged 1 commit into
trunkfrom
fix/pwa-link-capture-and-sw-reload-loop

Conversation

@epeicher
Copy link
Copy Markdown
Collaborator

@epeicher epeicher commented May 12, 2026

Summary

Two related PWA bugs:

  1. External links captured into the PWA. Manifest declared scope: '/', so every same-origin URL was in-scope of the installed app. Chrome's link-capturing routed clicks like the Comments "In response to" links (which point at front-end posts) into a standalone PWA window instead of opening a browser tab.
  2. Infinite reload loop with DevTools "Update on reload." Chrome's "Application → Service Workers → Update on reload" forces a SW install + activate on every navigation even when the SW bytes are byte-identical. The controllerchange handler reloaded the page on every activation, driving an infinite cycle inside the PWA.

What changed

  • Narrowed scope to /wp-admin/ (includes/pwa.php). Front-end URLs are now out of scope, so Chrome lets them open in a regular browser tab. Internal /wp-admin/* navigation still stays inside the PWA.
  • Moved start_url to /wp-admin/index.php?desktop_mode_portal=1 so the launch path lands inside the new scope without relying on the /desktop-mode/ redirect.
  • Held id at the previous /desktop-mode/ value so Chrome treats existing installs as the same app and doesn't reset them.
  • Throttled SW-update reloads (src/pwa/sw-register.ts): if we already reloaded for a controllerchange within the last 30s, skip the next one. Phantom updates from DevTools can't cycle anymore. Real deploys keep working: the next reload past the throttle window picks up the new bundle.

Test plan

  • Reinstall the PWA after deploy so Chrome picks up the new manifest.
  • In the PWA: open Comments, click an "In response to" link. Expect it to open in a browser tab.
  • In a regular browser tab with Desktop Mode enabled: same click, same expectation.
  • Inside the PWA with DevTools "Update on reload" enabled: reload the window. Expect one auto-reload at most, then a steady state. No infinite "Service Worker was updated…" flood.
  • Verify the manifest at /desktop-mode/manifest.webmanifest shows "scope":"/wp-admin/", "start_url":".../wp-admin/index.php?desktop_mode_portal=1", "id":".../desktop-mode/".
  • Existing PWA installs continue to launch and report display-mode: standalone after the manifest change.
Open WordPress Playground Preview

Two related PWA bugs.

1. External links captured into the PWA. With manifest scope `/`,
   every same-origin URL was in-scope of the installed app, so Chrome
   re-routed clicks like the Comments "In response to" links (which
   point at front-end posts) into a standalone PWA window instead of
   a browser tab. Narrowing scope to `/wp-admin/` keeps internal
   admin navigations inside the PWA while letting front-end URLs
   open in a real browser tab as users expect. `start_url` moves to
   the post-redirect admin URL so the launch path still lands inside
   the new scope; `id` is held at the previous portal URL so
   existing installs aren't reset by Chrome.

2. Infinite reload loop with DevTools' "Update on reload". The flag
   forces SW install + activate on every navigation even when the SW
   bytes are byte-identical, and the controllerchange handler
   reloaded the page on every activation, ad infinitum. Throttle the
   reload via a 30s sessionStorage timestamp so phantom updates
   from DevTools no longer drive a cycle. Real deploys still trigger
   the next reload past the window.
@github-actions
Copy link
Copy Markdown

✅ WordPress Plugin Check Report

✅ Status: Passed

📊 Report

All checks passed! No errors or warnings found.


🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@epeicher epeicher merged commit 5d806f9 into trunk May 12, 2026
5 checks passed
@epeicher epeicher deleted the fix/pwa-link-capture-and-sw-reload-loop branch May 12, 2026 14:16
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