Closed ChristiaanScheermeijer closed 3 months ago
Visit the preview URL for this PR (updated for commit 97de0d5):
https://ottwebapp--pr475-feat-reload-site-wit-7m5ki8t4.web.app
(expires Thu, 25 Apr 2024 16:42:49 GMT)
🔥 via Firebase Hosting GitHub Action 🌎
Sign: c198f8a3a199ba8747819f7f1e45cf602b777529
The SW caused a quite aggressive cache, which could only be circumvented by hard-refreshing. When a new version has been released we want our users to immediately see these changes. Therefore I think auto-reload is a good approach.
The auto-reload will only happen when users visit the website in a new window/tab and not during their visit in the active tab. I approve.
@langemike hm, are you sure the current active tab won't be refreshed if we call registerSW
again? Do we also need to 'reregister' sw or can we just leave the body function empty, like onNeedRefresh: () => {}
?
The disadvantage of using this behavior is that the user can lose data in any browser windows/tabs in which the application is open and is filling in a form.
Btw, pretty nice implementation with react hooks (custom prompt is used): https://vite-pwa-org.netlify.app/frameworks/react.html#prompt-for-update
hm, are you sure the current active tab won't be refreshed if we call registerSW again? Do we also need to 'reregister' sw or can we just leave the body function empty, like onNeedRefresh: () => {}?
I could not find an easy answer to that while reading the docs and source code. I'm not too familiar with ServiceWorkers and I reasonably assumed that in-memory JS code will not cause onNeedRefresh
to be called within a active session. Of course we need to verify this.
@AntonLantukh the SW is only refreshed when opening the page, we don't periodically poll for new versions in active sessions. This means that losing data is limited to the following scenario:
So I think that:
Description
This small configuration change will ensure users will always use the latest version of the web app. Before, you need to visit the site, close it or clear the cache to ensure the latest version is used.
This is because the PWA will wait until a suitable moment to activate the "waiting" next version of the deployment. On many occasions, publishers (and we) want to be able to deploy fixes immediately.
Read more about this here:
https://vite-pwa-org.netlify.app/guide/auto-update.html
CC: @langemike