Title: [Service Worker] Can't update sw if in SAFE_MODE · Issue #22087 · angular/angular · GitHub
Open Graph Title: [Service Worker] Can't update sw if in SAFE_MODE · Issue #22087 · angular/angular
X Title: [Service Worker] Can't update sw if in SAFE_MODE · Issue #22087 · angular/angular
Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] Feature request [ ] Documentation issue or request [ ] Support request => Please do not submit support request here...
Open Graph Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] Feature request [ ] Documentation issue or request [ ] Support request => P...
X Description: I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] Feature request [ ] Documentation issue or request [ ] Support request ...
Opengraph URL: https://github.com/angular/angular/issues/22087
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Service Worker] Can't update sw if in SAFE_MODE","articleBody":"\u003c!--\r\nPLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.\r\n\r\nISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.\r\n-->\r\n\r\n## I'm submitting a...\r\n\u003c!-- Check one of the following options with \"x\" -->\r\n\u003cpre>\u003ccode>\r\n[ ] Regression (a behavior that used to work and stopped working in a new release)\r\n[x] Bug report \u003c!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[ ] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n\u003c/code>\u003c/pre>\r\n\r\n## Current behavior\r\nWhen the service worker is installed / initialized the first time, it fetches the `ngsw.json`. If the content of `ngsw.json` is not an valid json the sw goes into SAFE_MODE:\r\n\r\nhttps://github.com/angular/angular/blob/c8a1a14b87e5907458e8e87021e47f9796cb3257/packages/service-worker/worker/src/driver.ts#L320-L325\r\n\r\nFrom thereon it is impossible to update the service worker. If you call `SwUpdate.checkForUpdate()` it never resolves or rejects and no new fetch to `ngsw.json` is performed due to the fact that messages are ignored in SAFE_MODE:\r\n\r\nhttps://github.com/angular/angular/blob/c8a1a14b87e5907458e8e87021e47f9796cb3257/packages/service-worker/worker/src/driver.ts#L189-L193\r\n\r\nReplacing the wrong `ngsw.json` with the correct one does only resolve this issue if:\r\n* the service worker is unregistered (if `ngsw.json` did not contain json. for example it contains html)\r\n* or the sw is unregistered and the cache is cleared (if `ngsw.json` did contain a json. ex: `{ \"test\": 123 }`).\r\nThis also triggers the following error: `Error: Invariant violated (initialize): latest hash null has no known manifest`\r\n\r\nThis issue occurred on our firebase hosted app. It seems a cache sometimes returns a html page with a 2xx status instead of the `ngsw.json` and broke our service worker. We also needed to clear the cache and unregister the service worker on some mobile clients. It might be that firebase sends sometimes a wrong json file or there might be another way to lock the service worker in the SAFE_MODE with `latest hash null` error. \r\n\r\n## Expected behavior\r\n* It should be possible to update the sw with `SwUpdate.checkForUpdate()` when the sw is in SAFE_MODE\r\n* Maybe the sw should try to refetch the `ngsw.json`? I'm not sure when and if this would be the appropriated way to handle this issue.\r\n\r\n## Minimal reproduction of the problem with instructions\r\nRepo: https://github.com/sean-nicholas/test-angular-service-worker\r\n\r\n* run `npm run build`\r\n* `cd` into `dist``\r\n* change the content of `ngsw.json` to \r\n * For non json case: `asdjknkfdnjgdfkaslkdm` \r\n * For json case: `{ \"test\": 123 }`\r\n* run `http-server` (or something similar) in `dist` folder\r\n* goto localhost in incognito mode\r\n* you get the error\r\n * For non json case: `Unexpected token a in JSON at position 0`\r\n * For json case: `TypeError: Cannot convert undefined or null to object`\r\n* sw installation fails and sw goes into SAFE_MODE\r\n* reload & press the `Check for SW Update` Button\r\n* `Checking` will stay true and not fall back to false after a few ms\r\n* Replace the content of `ngsw.json` with the correct data\r\n\r\nFor non json case:\r\n* Unregister the sw & reload -> it works again\r\n\r\nFor json case:\r\n* Unregister the sw & reload\r\n* Error: `Error: Invariant violated (initialize): latest hash null has no known manifest` occures\r\n* `Check for SW Update` seems to work but if you reload it fails (does not resolve) again\r\n* Clear the cache, unregister the sw & reload -> it works again\r\n\r\n## What is the motivation / use case for changing the behavior?\r\nThe service worker should not lock itself into a state were it can not be updated anymore.\r\n\r\n\r\n## Environment\r\n\r\n\u003cpre>\u003ccode>\r\n\"@angular/animations\": \"^5.2.4\",\r\n\"@angular/cdk\": \"^5.2.0\",\r\n\"@angular/common\": \"^5.2.4\",\r\n\"@angular/compiler\": \"^5.2.4\",\r\n\"@angular/core\": \"^5.2.4\",\r\n\"@angular/forms\": \"^5.2.4\",\r\n\"@angular/http\": \"^5.2.4\",\r\n\"@angular/material\": \"^5.2.0\",\r\n\"@angular/platform-browser\": \"^5.2.4\",\r\n\"@angular/platform-browser-dynamic\": \"^5.2.4\",\r\n\"@angular/router\": \"^5.2.4\",\r\n\"@angular/service-worker\": \"^5.2.4\"\r\n\r\nBrowser:\r\n(Only tested in)\r\n- [x] Chrome (desktop) version 64.0.3282.140\r\n- [x] Chrome (Android) version 64.0.3282.137\r\n- [ ] Chrome (iOS) version XX\r\n- [ ] Firefox version XX\r\n- [ ] Safari (desktop) version XX\r\n- [ ] Safari (iOS) version XX\r\n- [ ] IE version XX\r\n- [ ] Edge version XX\r\n \u003c/code>\u003c/pre>\r\n","author":{"url":"https://github.com/sean-nicholas","@type":"Person","name":"sean-nicholas"},"datePublished":"2018-02-08T09:57:55Z","url":"https://github.com/angular/angular/issues/22087"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ae18075f-e978-d2fe-66d1-4fe76f9d0c3d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9380:33444D:1301DEA:194C49E:6B01258F |
| html-safe-nonce | 4638db4b6554e63390d2e0cbeef6940c028cb1cd4ea023ff9f574ed10f0ea467 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzgwOjMzNDQ0RDoxMzAxREVBOjE5NEM0OUU6NkIwMTI1OEYiLCJ2aXNpdG9yX2lkIjoiMzA4NzA5MTM2MDIxODU1NTc5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 85dbda9ddee41cb527847ec2ee43849dbbdf27b52b5daf52133e66a30b7362a9 |
| hovercard-subject-tag | issue:295449064 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/22087/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a476c8a5831d3fea6cf1e32fa229388d165d1f62b7be07f0c5cb93fce8a9b601/angular/angular/issues/22087 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a476c8a5831d3fea6cf1e32fa229388d165d1f62b7be07f0c5cb93fce8a9b601/angular/angular/issues/22087 |
| og:image:alt | I'm submitting a... [ ] Regression (a behavior that used to work and stopped working in a new release) [x] Bug report [ ] Feature request [ ] Documentation issue or request [ ] Support request => P... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sean-nicholas |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width