question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Worker Gets in loop on live reload after upgrade to Angular 14

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

compiler, service-worker, Don’t known / other

Is this a regression?

Yes

Description

After upgrading to Angular 14, when a change is made to html or js in visual studio code, the compiler will complete and the browser will refresh x times (sometimes around 20) when service worker is enabled. When it is disabled the browser will reload once. No console errors are present, the service worker shows as being installed successfully through dev tools

Please provide a link to a minimal reproduction of the bug

https://github.com/AnnaO555/angular14SW_BUG.git

Please provide the exception or error you saw

there was no exception, the browser gets stuck in a loop for a while

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 14.2.2
Node: 14.15.4
Package Manager: npm 6.14.10
OS: win32 x64

Angular: 14.2.1
... cdk, common, compiler, compiler-cli, core, elements, forms
... router, service-worker

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.1402.2
@angular-devkit/build-angular       14.2.2
@angular-devkit/core                14.2.2
@angular-devkit/schematics          14.2.2 (cli-only)
@angular/cli                        14.2.2
@angular/platform-browser           14.2.2
@angular/platform-browser-dynamic   14.2.2
@schematics/angular                 14.2.2 (cli-only)
typescript                          4.7.4
webpack                             5.74.0

Anything else?

cut down repro above

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
TimGelscommented, Sep 28, 2022

The workaround mentioned by @gkalpak seems to be working for me. If someone reads this and it still does not work, make sure to have unregistered / removed the service worker in the browser and try again.

1reaction
gkalpakcommented, Sep 20, 2022

Thx for the info, @AnnaO555. It is probably because the Angular CLI did not include the SW in the build with ng serve before 14.2.0.

If you don’t need the SW in dev mode (which you probably don’t), you could try setting a property (for example, serviceWorker: true/false) in your environment configs (setting it to true for production and false for dev) and then using that to configure the ServiceWorkerModule’s enabled property.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular PWA SwUpdate always trigger update and reload
I have a SwupdaterService and in production mode app always reload, like loop, without any updates. Here my service: export class ...
Read more >
Service worker in production - Angular
The service worker responds to requests made by the Angular application for resources or data from a local cache, without needing to wait...
Read more >
Top 18 Most Common AngularJS Developer Mistakes - Toptal
In this article you will learn about most common AngularJS developer ... The content and widget get reloaded, but we only want to...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Changed to make sure nested worker gets controlled if matching a service worker ... Fixed composited canvas element to update the layer configuration...
Read more >
Top 10 Mistakes Node.js Developers Make - AirPair
1.2 Automatic browser refresh ... Besides reloading the Node application when the source code changes, you can also speed up development for web ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found