fix(pwa): update gracefully if missing clients info #679
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.
I noticed a bug when testing out the new update UX from LIBS-237 / #672 in the dashboards app: in dev mode, loading the app uses the latest adapter code but still requires updating the service worker. The latest adapter code requested Clients info from the existing SW to determine if it should reload right away or show the reload confirmation modal for multiple tabs open, but the existing SW didn't contain the logic to respond to that request, and the Update action failed. (I don't think this should happen in production because the deployed app will use the old adapter code, which doesn't make that request)
This PR includes better handling in case the request for clients info fails for any reason, falling back to the reload confirmation modal if no response is received to prevent data loss.
Also, the logic for requesting clients info is improved somewhat to send the request to the most recent SW, which would have been able to respond correctly in the bug case described above. The timeout is decreased too, which improves UX in case of a failure.
If you want to test out a SW that doesn't respond to the
getClientsInfo
request to simulate an old SW while using the PWA app, you can comment out this line in service-worker.js and build the PWA package before starting the pwa-app again (or using theyarn build:pwa --watch
command -- also for the adapter too)