-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PWA regularly check for service worker updates and automaticially reload the page #1188
Conversation
…y reload the app.
I thought they have a standard way to detect it automatically? And have a prompt option. How is |
I was under that impression too, but apparently not - it did update itself (ninja edit, here I mean the ServiceWorker itself, not the PWA)/check (with autoUpdate option) on a new page load (either open a new tab or reload the current page). And that's how I understand this option alone works (it silently updates the ServiceWorker, not the webapp) on new page load (as this is actually not guaranteed with ServiceWorkers, there could be old ServiceWorkers open and somewhere in another tab and they would not get updated if a new tab loads a new version of a ServiceWorker). More info on updating ServiceWorkers: https://web.dev/articles/service-worker-lifecycle#updates EDIT: Sorry I really need to double check my comments before I send them, I was not very clear. So, 'autoUpdate' option mostly tells the VitePWA to update the ServiceWorker (which is shared between all tabs from the same address) when it detects that there is a new version (as this ServiceWorker is shared between multiple tabs, auto updating is not automatic in the sense of how we always get the latest version of the webpage itself - bar caching). Nothing much about updating the Webpage/PWA. I guess that could be handled smartly too, but a reload is the most foolproof method there is - so we need to turn that on with the registerSW 'immediate' option, which reloads the webpage/PWA immediately when the ServiceWorker gets updated (automaticially with 'autoUpdate'). And if we don't want to wait for a webpage reload (or any of the other update triggers here: https://web.dev/articles/service-worker-lifecycle#updates) we need to check for ServiceWorker updates ourselves - and they have some edge case handling in the provided sample. Not sure why they are not doing that automatically TBH. I was expecting that too. But apparently not, as it's not even mentioned in the linked VitePWA docs. |
It seems like the browser should automatically check for updates: https://web.dev/articles/service-worker-lifecycle#updates Maybe I misunderstand something? |
The browser is checking for an update in this cases:
The last two are not applicable, as we are not pushing or syncing anything to the ServiceWorker and we are not chaging the ServiceWorker URL. |
Why do we need the |
Because of the warning here: https://vite-pwa-org.netlify.app/guide/auto-update.html#automatic-reload Yes, having a prompt removes the need for |
|
Ok, just to be clear, so user configurable as a server setting? And do we make it just on/off or can the update check interval be configured too (eg. then I would still go with one setting, but if it's 0 then don't check, if it's more than 0 then use that as an update check interval)? |
We can make the interval configurable, if that's easy to implement. And zero means no updates. I think we should include it in the server attributes. |
I think if it works well, let's make it as a default, so some reasonable default value. |
So this is just a work in progress for now - but have to finish for today and comited to get some preliminary feedback. I moved everything to a React component and adapted it to use plain Snackbar like other similar functionality in Traccar. While tweaking this I tested it plenty, and it works very well. What remains is figuring out why "useAttributePreference" is erroring out on me and do basic cleanup around that. I'm thinking 1h as the default value (as this is also the 'default' in Vite PWA documentation). P.S: There is a big ol red warning that switching between 'autoUpdate' and 'prompt' while in production can be a pain, but from what I can see 'autoUpdate' did not make it into 5.9 so this won't be a problem: https://vite-pwa-org.netlify.app/guide/auto-update.html |
After stepping back from the monitor for a few minutes it dawned on me, that as the system is not initialized, I cannot access the user attributes. Moved it to a better location and it is ready for a review. |
modern/src/UpdateCheckPrompt.tsx
Outdated
<Button onClick={() => updateServiceWorker(true)}> | ||
{t('settingsReload')} | ||
</Button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use an icon button? Like this one:
https://mui.com/material-ui/material-icons/?query=ref&selected=Refresh
It looks better and also we can remove one of the strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Anton Tananaev <[email protected]>
Merged, thank you. |
Thank you very much for your patience. |
Hi,
I was working on the #1169 issue and when deploying to staging I noticed that my PWA (on phone or open in the browser) does not actually update automatically like I would presume with the
registerType: 'autoUpdate'
config option set.After a bit of digging I actually found two things missing:
I tested this and now it behaves like I would expect it to behave. The Traccar PWA now checks every hour, if there is a new version and if found updates the ServiceWorker and reloads the webpage automaticially.
On a somewhat related note, just to be sure, so you do prefer automatic reload instead of the update-popup-and-user-clicks-for-reload?