fix: add Safari/iOS fallback for controllerchange not firing in prompt mode#937
Open
lucas-spin wants to merge 1 commit into
Open
fix: add Safari/iOS fallback for controllerchange not firing in prompt mode#937lucas-spin wants to merge 1 commit into
lucas-spin wants to merge 1 commit into
Conversation
✅ Deploy Preview for vite-plugin-pwa-legacy ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #524
Problem
In prompt mode (
registerType: 'prompt'), after the user accepts the update andupdateSW(true)is called:wb.messageSkipWaiting()sendsSKIP_WAITINGto the waiting service workerself.skipWaiting()and activates'controlling'event (which wrapsnavigator.serviceWorker'scontrollerchange) to trigger the page reloadOn Safari/iOS (WebKit), step 3 fails silently —
controllerchangedoes not fire reliably, especially in standalone/home-screen mode. This leaves users stuck after clicking the refresh button, with no error and no reload.This is a well-documented WebKit limitation that has affected users since 2023 (see #524, which has been open with no fix).
Solution
Added a timeout-based fallback in
updateServiceWorker():How it works:
controllingfires within ~50ms → setscontrollingReceived = true→ timeout is a no-opcontrollingnever fires → after 2s the fallback triggers the reloadAdditional fix: The
_reloadPageparameter was previously unused (underscore-prefixed, never referenced). It's now wired up to gate the fallback — callers can passupdateSW(false)to skip the auto-reload if they handle it manually viaonNeedReload.Impact
controllerchangefires correctlyReferences
needRefresh#255 — "[WKWebview] Subsequent SW Updates Not Setting needRefresh"