-
-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.18.0 breaks registerType: "prompt"
#663
Comments
Why are you exposing In the meantime, can you test using the logic provided in the periodic sync for updates and exposing |
Good shout, this is completely redundant.
I'm seeing the same issue with this logic, here is the updated hook if you'd like to double check my changes: export function useUpdate() {
const {
needRefresh: [needRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegisteredSW(serviceWorkerUrl, serviceWorkerRegistration) {
setInterval(async () => {
if (!(!serviceWorkerRegistration?.installing && navigator)) {
return;
}
if ("connection" in navigator && !navigator.onLine) {
return;
}
const response = await fetch(serviceWorkerUrl, {
cache: "no-store",
headers: {
cache: "no-store",
"cache-control": "no-cache",
},
});
if (response?.status === 200) {
await serviceWorkerRegistration?.update();
}
}, 60 * 1000);
},
onRegisterError(error) {
console.error("SW registration error", error);
},
});
return { updateReady: needRefresh, updateServiceWorker };
} |
Can you try removing the interval in your local? I Will check your reproduction tmr (refresh the page once built second time). |
Removing I did a separate test to see what happens if we update the service worker with Chrome's dev tools (also with |
You Will need to avoid calling update if the sw also waiting to be activated, I guess the update will also trigger the event to active it |
It seems the problem is the heuristic time approach in worbox window to detect false positives: you can try awaiting 1 minute between builds (https://github.com/GoogleChrome/workbox/blob/v7/packages/workbox-window/src/Workbox.ts#L414) |
Thank you for all your help, looking forward to getting to the bottom of this.
This doesn't seem to help, even if I remove
I tried the following but the issue still occurs:
|
Cleanup the storage removing the sw, the logic is always 1 step behind, you don't need to wait 10 min. just 1 min. EDIT: I have no idea what's the behavior when using refresh from chrome dev tools, you can just await the periodic sync to refresh it or just refresh the page |
I think it's the same as calling
Sorry I'm not sure what you mean by this.
Sorry I'm not sure what you mean by this either. |
I'm going to revert last change, I need to review what's happening in workbox-window and the register module here, sw events seems to be wrong. |
I guess it is a problem with the heuristic time based and short sw periodic sync + update call (when precaching new sw and calling update) |
@alexlapwood can you try this approach (update signals and effect, I'm not a solid expert)? const [updateFound, setUpdateFound] = createSignal(false)
const [interval, registerInterval] = createSignal<ReturnType<typeof setInterval> | undefined>(undefined)
createEffect(() => {
if (updateFound())
clearInterval(interval())
}) then in your onRegisteredSW(swUrl, r) {
if (r) {
navigator.serviceWorker.ready.then((registration) => {
registration.addEventListener('updatefound', () => {
console.log('updatefound')
setUpdateFound(true)
})
})
registerInterval(setInterval(async () => {
if (!(!r.installing && navigator))
return
if (('connection' in navigator) && !navigator.onLine)
return
const resp = await fetch(swUrl, {
cache: 'no-store',
headers: {
'cache': 'no-store',
'cache-control': 'no-cache',
},
})
if (resp?.status === 200)
await r.update()
}, 20000))
}
} |
Your use of signals and effects looks good to me, but the same issue still occurs. Let me know if there's anything else I can do to help figure this one out. |
Expected behaviour
In 0.17.5 setting
registerType: "prompt"
behaved like this:serviceWorkerRegistration.update()
updateServiceWorker()
Observed behaviour
In 0.18.0 setting
registerType: "prompt"
behaves like this:serviceWorkerRegistration.update()
updateServiceWorker()
(causing another reload)Steps to reproduce
You can reproduce this issue using the following SolidJS hook:
I'm not sure if the title of this issue is correct, please change as needed.
The text was updated successfully, but these errors were encountered: