angular-docs-cn/packages/service-worker/worker/src
George Kalpakas 094538c0ce feat(service-worker): recover from `EXISTING_CLIENTS_ONLY` mode when there is a valid update (#31865)
Previously, when the ServiceWorker entered a degraded mode
(`EXISTING_CLIENTS_ONLY` or `SAFE_MODE`) it would remain in that mode
for the rest of the lifetime of ServiceWorker instance. Note that
ServiceWorkers are stopped by the browser after a certain period of
inactivity and a new instance is created as soon as the ServiceWorker
needs to handle an event (such as a request from the page). Those new
instances would start from the `NORMAL` mode.

The reason for this behavior is to err on the side of caution: If we
can't be sure why the ServiceWorker entered the degraded mode, it is
risky to try recovering on the same instance and might lead to
unexpected behavior.

However, it turns out that the `EXISTING_CLIENTS_ONLY` mode can only be
a result of some error happening with the latest version (e.g. a hash
mismatch in the manifest). Therefore, it is safe to recover from that
mode once a new, valid update is successfully installed and to start
accepting new clients.

This commit ensures that the mode is set back to `NORMAL`, when (a) an
update is successfully installed and (b) the current mode is
`EXISTING_CLIENTS_ONLY`.

Besides making the behavior more predictable (instead of relying on the
browser to decide when to terminate the current ServiceWorker instance
and create a new one), this change can also improve the developer
experience:
When people notice the error during debugging and fix it by deploying a
new version (either to production or locally), it is confusing that the
ServiceWorker will fetch and install the update (as seen by the requests
in the Network panel in DevTools) but not serve it to clients. With this
change, the update will be served to new clients as soon as it is
installed.

Fixes #31109

PR Close #31865
2019-09-04 15:41:04 -07:00
..
adapter.ts fix(service-worker): registration failed on Safari (#31140) 2019-06-24 14:58:58 -07:00
api.ts fix(service-worker): several misc fixes for corner cases 2017-10-05 13:27:31 -07:00
app-version.ts feat(service-worker): support multiple apps on different subpaths of a domain (#27080) 2019-03-21 12:07:56 -04:00
assets.ts refactor(service-worker): make second parameter to `Adapter#parseUrl()` optional (#27080) 2019-03-21 12:07:56 -04:00
data.ts refactor(service-worker): remove redundant cache operation (#30977) 2019-06-27 09:52:29 -07:00
database.ts feat(service-worker): introduce the @angular/service-worker package (#19274) 2017-09-28 16:18:12 -07:00
db-cache.ts feat(service-worker): support multiple apps on different subpaths of a domain (#27080) 2019-03-21 12:07:56 -04:00
debug.ts fix(service-worker): several misc fixes for corner cases 2017-10-05 13:27:31 -07:00
driver.ts feat(service-worker): recover from `EXISTING_CLIENTS_ONLY` mode when there is a valid update (#31865) 2019-09-04 15:41:04 -07:00
error.ts fix(service-worker): do not blow up when caches are unwritable (#26042) 2018-09-24 09:53:39 -07:00
idle.ts fix(service-worker): several misc fixes for corner cases 2017-10-05 13:27:31 -07:00
manifest.ts fix(service-worker): detect new version even if files are identical to an old one (#26006) 2019-03-05 09:41:44 -08:00
msg.ts feat(service-worker): introduce the @angular/service-worker package (#19274) 2017-09-28 16:18:12 -07:00
service-worker.d.ts refactor(service-worker): update tests based of review feedback (#25860) 2018-11-01 15:13:32 -07:00
sha1.ts perf: don't create holey arrays (#32155) 2019-08-21 08:27:43 -07:00