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 state was retained between passes, leading to an incorrect result #2725

Open
tusharmath opened this issue Jul 23, 2017 · 2 comments
Labels

Comments

@tusharmath
Copy link

Scenario
I use service worker to render shells on the clientside itself this gives me a significant boost in time to first paint. To render the shell I need to create the complete HTML on the client side. The HTML contains links to assets such as CSS and JS. These assets are generated via webpack and have a hash appended to their name. For that I need to make a request inside the service worker to fetch the manifest file. The file looks something like this —

// inside sw.js
const manifestJSON = fetch('/webpack.manifest.json').then(i => i.json())

/* response */
{
  "main.css": "main-4da4b1f47abac15d0459884a4218ebe0.css",
  "main.js": "main-7f2d1dd16a24ae09824e.js",
  "sw.js": "sw-1cf6e8eb12a4299116e2.js"
}

Inside my sw.js, I was making the HTTP request in the beginning of the file. This is an issue because when the service worker starts and if the application is offline this time, the promise returned by the fetch above will simply throw an exception. As of now we will still be getting a 100/100 PWA score because the in the tests, fetch happens only once and the response is saved in the variable manifestJSON and reused for all other tests.

Where as on a mobile device the SW automatically stops after sometime. Visiting the page again in offline mode restarts the SW but this time it isn't able to fetch the manifest file which causes the it to crash.

General Test Case

  • Register/activate a service worker successfully
  • Stop the service worker
  • Go offline
  • Reload page

Pass Case
200 response is still received

Fail Case
Page Fails to load

Current Case
A false positive is received.

I would be glad to send a PR if someone is accepting :)

@patrickhulce
Copy link
Collaborator

Thanks for the detailed report! It's also possible that #709 will address this issue for you though killing the service worker in between passes would be an extra precaution we could take. 👍

@paulirish
Copy link
Member

Aye.

  1. We think Update throttling/cache/js state on the SW target #709 might fix this because the SW will be set correctly.
  2. We could possibly stop the service worker between the passes. Might as well. If you're interested in contributing this, we could review that PR. It'll be hard though!

@paulirish paulirish changed the title Add a test for stopped then started service worker Service Worker state was retained between passes, leading to an incorrect result Sep 28, 2017
@paulirish paulirish added pwa and removed pwa labels Apr 16, 2024
@adrianaixba adrianaixba reopened this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants