-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Web] Don't force-reload the Service Worker #561
Conversation
536ee3f
to
746f215
Compare
This PR solves one issue but creates another – despite the |
I'm confused here. Is the problem that the service worker upgrades itself to newer copies of the service worker code, but we initiate that? Is there a way to reject updates? Why apply the update in the middle of a session when we could choose to only update at app bootup? Or when there are no messages going on (consider, for example, triggers at a new session at at some number of minutes since the last activity from a session) |
@dmsnell I still find service workers confusing.
I'm starting to think the only bulletproof solution here might be doing a PWA. This way we could auto-update on return, but keep using the old version if you open a new playground in an active browsing session. |
When mounting local directories in #548, problems appeared in development builds because the dev environemnt runs a separate server for the website that wraps the iframe and the for the assets inside the iframe, the "remote." In this patch we're adjusting the config for the outer website server so that we can proxy requests for the internal frame through the same origin. This is done by adding a prefix to the URL for the dev assets on the outer frame, which then is used in a proxy rule to decide what to route. This means that OPFS handles can be shared between the two sides of the iframe, which normally happens in production since they both come from the same origin.
…er start after the remote
So far I found three problems: * Message handler in broadcastMessageAwaitReply() seems to get bound after the response is received by the service worker. Fix: bind it before dispatching the message * Setting the iframe source in bindMessageHandler() triggers a request message that is handled but the response to that message is not processed in the service worker. Not sure why. * Auto-reloading the service worker when it's updated thrashes any postMessage communication that's in progress at the moment of calling update() and skipWaiting(). Ideal UX would be to figure out that flow, but easy fix is to reload the page after invalidating the stale service worker
8b119f5
to
bf82ce6
Compare
I removed the entire concept of detecting the service worker version and enforcing an update on mismatch. I just realized the browsers give us a lot by default:
The only case this doesn't cover is "the newly deployed site is backwards–incompatible and requires the new worker". Let's handle that case as follows:
The latter would mean reloading work-in-progress tabs for folks who:
Since that could be potentially destructive, that new tab could ask for permissions, e.g.
|
f1e3cbf
to
10e6625
Compare
Removes the entire concept of detecting the service worker version and enforcing an update on mismatch. Auto-reloading the service worker when it's updated thrashes any `postMessage` communication that's in progress at the moment of calling `skipWaiting()`. This causes Playground to hang at the "login" step in #559. However, the browsers handle a lot by default: * `registration.update()` method downloads the new service-worker.js file and compares it byte-by-byte with the existing one * The previous service worker won't die until all the browser tabs it serves are closed * The new service worker will automatically replace the previous one afterwards The only problem remains deploying a website that is backwards–incompatible with the previous service worker. This is tracked separately in #566 Co-authored-by: Dennis Snell <dennis.snell@automattic.com>
Description
Auto-reloading the service worker when it's updated thrashes any
postMessage
communication that's in progress at the moment of callingskipWaiting()
. This causes Playground to hang at the "login" step in #559.This PR removes the entire concept of detecting the service worker version and enforcing an update on mismatch.
The browsers handle a lot by default:
registration.update()
method downloads the new service-worker.js file and compares it byte-by-byte with the existing oneThe only problem remains deploying a website that is backwards–incompatible with the previous service worker.
Let's handle that case as follows:
cc @ellatrix @dmsnell