Skip to content
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

It's at least theoretically possible for the service worker to fail to load lazy modules #214

Open
helloworld12321 opened this issue Jan 23, 2021 · 1 comment
Labels

Comments

@helloworld12321
Copy link
Member

From the docs, it looks like there's a specific set of events that can trap the service worker in an unrecoverable state. (Here "unrecoverable" means that the user has to refresh the page to make the website work.)

I'll try to give my best description of the issue, but I'm still new to working with service workers, so I may have gotten some of the details wrong. If in doubt, I've linked to a primary source at the bottom of this description. :)


Basically what needs to happen to create the unrecoverable state is:

  1. A new version gets deployed to the server.
  2. The service worker is still serving the old main module.
  3. The browser doesn't have a cached copy of the old lazy module.
  • (because it got reclaimed for disk space, or something like that.)
  1. The server no longer has the old lazy module.
  • (it only has the newest version.)

At some point, the web page will try to load the old lazy module, and the service worker will need to handle that request.

But, the service worker doesn't have a local copy (the old lazy isn't in the cache)
and the service worker can't request a copy from the server (since the server doesn't have the old lazy anymore).

This is an unrecoverable state.

To fix the problem the user just needs to reload the web page; if they do that, all modules will have updated to the latest version.


Angular's SwUpdate service is able to detect this scenario automatically and prompt the user to refresh; I asked @floogulinc, and he says we should probably be doing that.

For more details, see: https://angular.io/guide/service-worker-communications#handling-an-unrecoverable-state

(PS: I don't know exactly what steps you can take to reproduce this bug; I only know that it theoretically exists. 🤷🏻‍♂️ I'm sure there's some way to clear the lazy module from your cache by hand, but I'd have to look up the exact process. 🙃 Sorry about that!)

@helloworld12321 helloworld12321 added bug Something isn't working service worker labels Jan 23, 2021
@helloworld12321
Copy link
Member Author

This isn't a very high priority bug, but I'm at least making a note of it here so we don't forget that it exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant