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 does not fetch new version of the app if the version is same as a previous version #24338

Closed
arikanorh opened this Issue Jun 7, 2018 · 5 comments

Comments

Projects
None yet
5 participants
@arikanorh
Copy link

arikanorh commented Jun 7, 2018

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

I build a sample hello world project with angular cli and add service worker. And i added update handler on my main project to show some notification. Lets say this is version A. I did a prod build and all is well. I changed to style css lets say body {background:red} and i build again (version B) while http-server is still up. I refreshed page and service worker catched the diff and show the notication.So far so good,

Then i reverted css change and end up with a version C which is identical to version A in terms on file contents.

Then build and deploy again. At this time when i refresh the app, the service worker doesnt fetch the new files and still show the version B.

Expected behavior

Service worker should fetch the version C and trigger an update showing notification

Minimal reproduction of the problem with instructions

  1. Create a new app with angular cli and add service worker
  2. Build for prod and serve with http-server
  3. While http-server is up change style.css to backgroun:red
  4. Build deploy
  5. Refresh page and you will see red background
  6. Then remove background:red and make the file exactly same as before
  7. Build deploy
  8. Refresh the page. At this time sw wont recognize new files even after several refreshes.

What is the motivation / use case for changing the behavior?

Sometimes developers make a rollback after a detecting a fatal bug after a new release. With this bug, the revert wont go use

Environment


Angular version: 6.0.4


Browser:
- [ ] Chrome (desktop) version 69
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

@ngbot ngbot bot added this to the needsTriage milestone Jun 8, 2018

@gkalpak gkalpak added the freq1: low label Jun 8, 2018

@gkalpak

This comment has been minimized.

Copy link
Member

gkalpak commented Jun 8, 2018

Indeed, this happens due to this check:

// Check whether this is really an update.
if (this.versions.has(hash)) {
return false;
}

I guess this is to account for proxies serving outdated content or something.
One solution I can think of is adding an extra field (e.g. "random" number or date) in the manifest and ensuring it is taken into account when computing the version's hash. This way we ensure (with a high enough probability) that each build will be distinguishable from all other builds.

(Taking this one step further, it would be even better if we kept the "uid" distinct from the hash, so that we could detect that the latest version is identical with a previous one and re-use that without having to re-fetch assets (even if from cache).)

gkalpak added a commit to gkalpak/angular that referenced this issue Sep 18, 2018

fix(service-worker): detect new version even if files are identical t…
…o an old one

Previously, if an app version contained the same files s an older
version (e.g. making a changing, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes angular#24338

gkalpak added a commit to gkalpak/angular that referenced this issue Sep 18, 2018

fix(service-worker): detect new version even if files are identical t…
…o an old one

Previously, if an app version contained the same files s an older
version (e.g. making a changing, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes angular#24338

gkalpak added a commit to gkalpak/angular that referenced this issue Sep 18, 2018

fix(service-worker): detect new version even if files are identical t…
…o an old one

Previously, if an app version contained the same files as an older
version (e.g. making a change, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes angular#24338
@javierforero

This comment has been minimized.

Copy link

javierforero commented Nov 7, 2018

@gkalpak do you have any recommendations on how to fix this meanwhile your PR gets merged?

My Angular service worker doesn't seem to recognize app updates if I roll back to an older version of the app I am working on. I'm new to PWA's so any advice would be greatly appreciated

@gkalpak

This comment has been minimized.

Copy link
Member

gkalpak commented Nov 7, 2018

Unfortunately, I can't think of any work around that would allow rollbacks to work. The obvious (but tedious) solution is to change something in ngsw-config.json to make it different than the old one (if I'm not mistaken, it could be just something in appData).

@XavierDupessey

This comment has been minimized.

Copy link

XavierDupessey commented Nov 29, 2018

Bug still exists in Angular 7.1.1.

The workaround suggested by @gkalpak works: change anything in ngsw-config.json (ngsw.json in dist folder) > appData. Thanks !

gkalpak added a commit to gkalpak/angular that referenced this issue Jan 16, 2019

fix(service-worker): detect new version even if files are identical t…
…o an old one

Previously, if an app version contained the same files as an older
version (e.g. making a change, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes angular#24338
@maxisam

This comment has been minimized.

Copy link
Contributor

maxisam commented Jan 29, 2019

If anyone deploys the app with CI/CD, you can use it to replace properties in ngsw.json to make this work like what @gkalpak suggested.

Here is how to do it in Azure DevOps

image

add variables like

image

because deploymentId will change when there is a deployment every time, so it can make rollback work properly.

gkalpak added a commit to gkalpak/angular that referenced this issue Mar 5, 2019

fix(service-worker): detect new version even if files are identical t…
…o an old one

Previously, if an app version contained the same files as an older
version (e.g. making a change, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes angular#24338

AndrewKushnir added a commit that referenced this issue Mar 5, 2019

fix(service-worker): detect new version even if files are identical t…
…o an old one (#26006)

Previously, if an app version contained the same files as an older
version (e.g. making a change, then rolling it back), the SW would not
detect it as the latest version (and update clients).

This commit fixes it by adding a `timestamp` field in `ngsw.json`, which
makes each build unique (with sufficiently high probability).

Fixes #24338

PR Close #26006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.