Steps to reproduce in v0.21.0:
git clone https://github.com/vite-pwa/vite-plugin-pwa.git
- Run examples as in docs
- Answer questions:
- Select a framework: preact (bug is not related to preact)
- Select a strategy: injectManifest
- Select a behavior: Prompt for update
- Enable periodic SW updates? yes
- Unregister SW? no
- Open
https://localhost in Chrome in incognito mode
- In prompt App ready to work offline: click Close
- Wait for 1 minute as suggested in docs
- Add
console.log('foobar') to examples/preact-router/src/main.tsx`
- Repeat step 2 and 3.
- In prompt New content available, click on reload button to update. click Reload
- Problem: Page does not reload
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:
|
wb?.addEventListener('controlling', (event) => { |
|
if (event.isUpdate) |
|
window.location.reload() |
|
}) |
When I add
// examples/preact-router/src/prompt-sw.ts
import { clientsClaim } from 'workbox-core'
//...
clientsClaim()
Then the controlling event fires, however with incorrect event.isUpdate = false and in effect reload still doesn't happen
BTW: 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
Steps to reproduce in v0.21.0:
git clone https://github.com/vite-pwa/vite-plugin-pwa.githttps://localhostin Chrome in incognito modeconsole.log('foobar') toexamples/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
controllingevent doesn't fire in this case:vite-plugin-pwa/src/client/build/register.ts
Lines 85 to 88 in 95142eb
When I add
Then the
controllingevent fires, however with incorrectevent.isUpdate = falseand 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.isUpdatePossibly related: #256