fix(pwa): narrow scope to /wp-admin/ and throttle SW reloads#181
Merged
Conversation
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.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
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.
Summary
Two related PWA bugs:
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.controllerchangehandler reloaded the page on every activation, driving an infinite cycle inside the PWA.What changed
scopeto/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.start_urlto/wp-admin/index.php?desktop_mode_portal=1so the launch path lands inside the new scope without relying on the/desktop-mode/redirect.idat the previous/desktop-mode/value so Chrome treats existing installs as the same app and doesn't reset them.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
/desktop-mode/manifest.webmanifestshows"scope":"/wp-admin/","start_url":".../wp-admin/index.php?desktop_mode_portal=1","id":".../desktop-mode/".display-mode: standaloneafter the manifest change.