pcb icon indicating copy to clipboard operation
pcb copied to clipboard

autoUpdate interval not firing

Open solace opened this issue 7 years ago • 3 comments

Hi,

I'm using react-boilerplate and have used https://zach.codes/handling-client-side-app-updates-with-service-workers/ as a reference for getting automatic updates running on a SPA.

The plugin is configured as:

new OfflinePlugin({
  ...
  updateStrategy: 'changed',
  autoUpdate: 1000 * 60 * 2,
 
  ServiceWorker: {
    events: true,
    navigateFallbackURL: '/',
  },
}),

And

OfflinePluginRuntime.install({
  onUpdateReady: () => OfflinePluginRuntime.applyUpdate(),
  onUpdated: () => window.swUpdate = true,
});

However, updates don't seem to be firing at the 2 minute intervals this suggests it should be doing.

I'm presently triggering updates by having certain actions manually invoking

if ('serviceWorker' in navigator) {
    navigator.serviceWorker.ready.then(function(registration) {
      registration.update();
    });
  }

Which works, and sets window.swUpdate as expected. But I'm not sure if I've misunderstood how the autoUpdate interval works to get it to do this automatically.

solace avatar Dec 05 '17 15:12 solace

@solace Hi. It supposed to work. Are you sure it isn't calling updates at all?

NekR avatar Dec 07 '17 09:12 NekR

I've tried adding console.logs to each event that can be configured in install, and changing the autoUpdate value to a shorter interval for testing. As it's an SPA, I don't have other routes to nav to to see if it makes a difference, but minutes pass without any of the log messages appearing until I manually invoke registration.update either from the console, or through an action in the SPA.

Do you have any recommendations for how else I can test this, or have any suggestions for where I should look to diagnose the issue?

Thanks

solace avatar Dec 08 '17 17:12 solace

@solace hey. If you're still using it, I'll be happy to help and debug it if you could provide a test-case/demo repo with this issue happening. I'm not sure how to solve it otherwise, unfortunately.

NekR avatar Mar 08 '18 07:03 NekR