-
Notifications
You must be signed in to change notification settings - Fork 27.1k
ServiceWorker doesn't always trigger .available method #24810
Copy link
Copy link
Closed
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:
Current behavior
The service worker doesn't always trigger .available() method after when it downloads new files in the background. Sometimes it does and sometimes it doesn't and is rather random.
Here is my code that checks for updates every 2.5 mins.
File app.component.ts
private setupServiceWorker(): void {
if ( this.swUpdate.isEnabled && environment.allowServiceWorker ) {
// Check for update
this.appUpdateIntervalSub = interval( 1000 * 60 * 2.5 ).subscribe( () => {
this.swUpdate.checkForUpdate();
} );
// New app version is available
this.appUpdateAvailableSub = this.swUpdate.available.subscribe( () => {
console.log('SW Available');
// New version of app is available - notify user to refresh browser
this.showAppUpdateMessage = true;
});
}
}
I do not get the console.log('SW Available') messages everytime.
Route data of /ngsw/state:
NGSW Debug Info:
Driver state: EXISTING_CLIENTS_ONLY (Degraded due to failed initialization: Hash mismatch (cacheBustedFetchFromNetwork): https://myDomainName/index.html: expected c4f0a150ff312ec887e7be08af365d271fd9f06c, got bfe58f87b8ea9c0cd8adae7224ebb955cdece43e (after cache busting)
Error: Hash mismatch (cacheBustedFetchFromNetwork): https://myDomainName/index.html: expected c4f0a150ff312ec887e7be08af365d271fd9f06c, got bfe58f87b8ea9c0cd8adae7224ebb955cdece43e (after cache busting)
at PrefetchAssetGroup.<anonymous> (https://myDomainName/ngsw-worker.js:670:31)
at Generator.next (<anonymous>)
at fulfilled (https://myDomainName/ngsw-worker.js:304:58))
Latest manifest hash: d88b815671b5211492c12506ee12732d482d6dab
Last update check: 2m2s134u
=== Version 1d60db65d5801d39103c347b22b9b583b2c1a31d ===
Clients:
=== Version d88b815671b5211492c12506ee12732d482d6dab ===
Clients:
=== Idle Task Queue ===
Last update tick: 2m7s567u
Last update run: 2m2s566u
Task queue:
Debug log:
[36m42s792u] Ignoring invalid request: 'only-if-cached' can be set only with 'same-origin' mode Driver.fetch(https://myDomainName/, cache: only-if-cached, mode: no-cors)
[34m40s732u] Error(Hash mismatch (cacheBustedFetchFromNetwork): https://myDomainName/index.html: expected c4f0a150ff312ec887e7be08af365d271fd9f06c, got bfe58f87b8ea9c0cd8adae7224ebb955cdece43e (after cache busting), Error: Hash mismatch (cacheBustedFetchFromNetwork): https://myDomainName/index.html: expected c4f0a150ff312ec887e7be08af365d271fd9f06c, got bfe58f87b8ea9c0cd8adae7224ebb955cdece43e (after cache busting)
at PrefetchAssetGroup.<anonymous> (https://myDomainName/ngsw-worker.js:670:31)
at Generator.next (<anonymous>)
at fulfilled (https://myDomainName/ngsw-worker.js:304:58)) initializeFully for 1bab97af18ccaca1f545df20278dd011cd0ce7d1
Expected behavior
It should trigger .available() method of ServiceWorker update class each time a new version is of the app is downloaded in background.
Minimal reproduction of the problem with instructions
Its a bug that appears randomly so cannot give Reproduction steps
What is the motivation / use case for changing the behavior?
The users cannot be notified that a new app version has been released and so refresh the browsers.
Environment
Angular CLI: 6.0.8
Node: 10.1.0
OS: darwin x64
Angular: 6.0.7
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3
Browser:
- [ X ] Chrome (desktop) version 67
For Tooling issues:
- Node version: 10.1.0
- Platform: Mac
Others:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels