Skip to content

Bug: Prompt for update doesn't reload page on first update #789

@piotr-cz

Description

@piotr-cz

Steps to reproduce in v0.21.0:

  1. git clone https://github.com/vite-pwa/vite-plugin-pwa.git
  2. Run examples as in docs
  3. 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
  4. Open https://localhost in Chrome in incognito mode
  5. In prompt App ready to work offline: click Close
  6. Wait for 1 minute as suggested in docs
  7. Add console.log('foobar') to examples/preact-router/src/main.tsx`
  8. Repeat step 2 and 3.
  9. In prompt New content available, click on reload button to update. click Reload
  10. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions