Open piotr-cz opened 6 days ago
The issue is related to checks for event.isUpdate
, which is false for for first service worker update.
The event.isUpdate
property doesn't indicate that service worker has been updated, but the fact that it's an update to service worker that was available when workbox-window was registered.
It's set at workbox-window registration, and not updated later on:
// Set this flag to true if any service worker was controlling the page
// at registration time.
this._isUpdate = Boolean(navigator.serviceWorker.controller);
For the controlling
event it's description is:
True if a service worker was already controlling when this service worker was registered.
It doesn't mean that service worker has been updated from previous version
I think it's safe to remove all if (event.isUpdate)
checks.
Related issue in workbox repo: https://github.com/GoogleChrome/workbox/issues/3377
Steps to reproduce in v0.21.0:
git clone https://github.com/vite-pwa/vite-plugin-pwa.git
https://localhost
in Chrome in incognito modeconsole.log('foobar') to
examples/preact-router/src/main.tsx`This happens only for first service worker update. For any subsequent updates, clicking on Reload reloads the page. Reproduction should be run in incognito mode to simulate first update
Seems that the
controlling
event doesn't fire in this case:https://github.com/vite-pwa/vite-plugin-pwa/blob/95142ebc588dea3d9376a2eb4affe086f19a7395/src/client/build/register.ts#L85-L88
When I add
Then the
controlling
event fires, however with incorrectevent.isUpdate = false
and in effect reload still doesn't happenBTW: I've noticed that in Workbox Docs > Use cases and recipes > Handling service worker updates with immediacy there is no check for the
event.isUpdate
Possibly related: #256