I have an app that registers a service worker and gives the user the chance to trigger a service worker update when a new service worker is waiting. Everything seems to be functioning well on Android, and it's also functioning fairly well on iOS. However, in standalone mode on iOS, after making one service worker update, it seems like the app keeps trying to install the same service worker over and over again.
Using an iPad running iPadOS 16.4.1, I take the following steps to produce the issue:
I've confirmed via Safari's Web Inspector that service worker A is running initially, that service worker B is then loaded and made active, that it is service worker B that's running after the app is killed and then restarted, and that the subsequently loaded service worker is a copy of service worker B.
Is this a known limitation/quirk of PWAs running on Apple devices, or does it sound like something's gone amiss on my end to cause it?
I'm not running into the same issue when I kill the PWA while it's still running service worker A and service worker B hasn't been deployed (it's only after I've updated the service worker at least once that the issue crops up). So my current guess is that perhaps on iOS the PWA retains information about the original service worker it was installed with and compares against that original service worker rather than the currently active service worker when looking for updates. I haven't been able to find any documentation that supports that theory yet though.
I'm not entirely sure why this fixed the issue, but in case it helps others:
I was making a call to the service worker's registration.update() method on a set interval to check for updates, and originally I was doing so within my service worker's code. Simply moving that logic to the app code and making the registration.update() call from there instead of from the service worker ended up fixing the problem for me. Since it works just fine on Android either way and since the documentation for the update method indicates that a byte-by-byte identical service worker shouldn't be installed as a new service worker, I suspect this is just an iOS quirk.