ilan-schemoul / meteor-service-worker

An universal service worker for meteor apps
MIT License
137 stars 26 forks source link

Fix: Uncaught (in promise) TypeError: Failed to execute 'clone' #3

Closed mrauhu closed 7 years ago

mrauhu commented 7 years ago

Hello @NitroBAY.

I'm found a bug in the Meteor Service Worker.

How to reproduce

  1. Add the sw.js to your Meteor project in folder /public.
  2. Run meteor command.
  3. Open the Developer Tools, then navigate to the Console tab in your browser.
  4. Open address: http://localhost:3000
  5. Change any client file, and wait for the Meteor Client reload
  6. You got multiple errors:
sw.js:56 Uncaught (in promise) TypeError: Failed to execute 'clone' on 'Response': Response body is already used
    at caches.open.then.cache (http://localhost:3000/sw.js:45:80)
sw.js:56 Uncaught (in promise) TypeError: Failed to execute 'clone' on 'Response': Response body is already used
    at caches.open.then.cache (http://localhost:3000/sw.js:56:80)

How to fix

Use the clonedResponse variable, not the response.clone() directly.

ilan-schemoul commented 7 years ago

Hello, Your fix is probably working. But I'm not sure why it's not working for now, why is response consumed ? response.clone(); shouldn't consume, return response; consumes but as also stop the callback's execution. I must miss something as I don't know why when the script is at response.clone() response is already consumed. Thanks anyway @mrauhu, it should fix #2.