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

Service Worker should check for updates on every navigation #20877

Closed
alxhub opened this issue Dec 7, 2017 · 5 comments
Closed

Service Worker should check for updates on every navigation #20877

alxhub opened this issue Dec 7, 2017 · 5 comments

Comments

@alxhub
Copy link
Contributor

@alxhub alxhub commented Dec 7, 2017

Currently the SW checks for updates on cold starts. Cold starts are unpredictable. This technique is generally fine in production but makes it hard for developers to verify the update process.

The SW should instead always fetch ngsw.json on navigation.

@gkalpak
Copy link
Member

@gkalpak gkalpak commented Dec 8, 2017

But you can manually check for updates with SwUpdate, right?
At least I would make it configurable (e.g. when importing the ServiceWorkerModule). Some strategies could be:

  • Check on cold starts.
  • Check on navigation.
  • Check every X amount of time.
@webmaxru
Copy link
Member

@webmaxru webmaxru commented Dec 8, 2017

What I've found - it's enough to just subscribe to updates to trigger the update check w/o need for the SW cold start (as well as there is no need to use checkForUpdate() explicitly):

 this.swUpdate.available.subscribe(event => {
     //no-op
 });

With this code, if a new version deployed it will show up on the 2nd refresh

@alxhub alxhub self-assigned this Dec 8, 2017
alxhub added a commit to alxhub/angular that referenced this issue Dec 14, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users, This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes angular#20877
alxhub added a commit to alxhub/angular that referenced this issue Dec 14, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users, This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes angular#20877
alxhub added a commit to alxhub/angular that referenced this issue Dec 14, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users. This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes angular#20877
alxhub added a commit to alxhub/angular that referenced this issue Dec 15, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users. This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes angular#20877
@alxhub
Copy link
Contributor Author

@alxhub alxhub commented Dec 15, 2017

@webmaxru do you have a stable reproduction of that? Subscribing alone sends no messages to the SW and shouldn't affect behavior in any way...

@webmaxru
Copy link
Member

@webmaxru webmaxru commented Dec 15, 2017

@alxhub I can't reproduce it precisely anymore. Maybe it was a combo of normal VS incognito mode and existing VS new tabs. I'll continue exploring during this weekend

Service Worker automation moved this from Critical to Done Dec 15, 2017
alxhub added a commit that referenced this issue Dec 15, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users. This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes #20877
sreevani-ship-it added a commit to ExpertSupport/angular that referenced this issue Dec 18, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users. This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes angular#20877
alxhub added a commit that referenced this issue Dec 20, 2017
Currently the Service Worker checks for updates only on SW startup,
an event which happens frequently but also nondeterministically. This
makes it hard for developers to observe the update process or reason
about how updates will be delivered to users. This problem is
exacerbated by the DevTools behavior of keeping the SW alive
indefinitely while opened, effectively preventing the page from
updating at all.

This change causes the SW to additionally check for updates on
navigation requests (app page reloads). This creates deterministic
update behavior, and is much easier for developers to reason about.
It does leave the old update-on-SW-startup behavior in place, as
removing that would be a breaking change.

Fixes #20877
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 13, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants