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

MSW fails to start Mock because worker update() fails. #2006

Open
4 tasks done
lazpit opened this issue Jan 30, 2024 · 1 comment
Open
4 tasks done

MSW fails to start Mock because worker update() fails. #2006

lazpit opened this issue Jan 30, 2024 · 1 comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:browser Related to MSW running in a browser

Comments

@lazpit
Copy link

lazpit commented Jan 30, 2024

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Browsers

Chromium (Chrome, Brave, etc.), Firefox

Reproduction repository

https://codesandbox.io/p/devbox/msw-react-xx1c8

Reproduction steps

Can't make a reproduction repository, it depends if my backend is accessible. If backend is running, MSW mock starts and do his job. MSW fails to start mock with SetupWorker.start() when server is not reachable.

To reproduce, I have to stop my backend that serves assets and bundle.js resources.

Current behavior

The function that find existing registration of the service worker is trying to update it and returns fetch error below because service-worker.js resources is not accessible.

image
image

getWorkerInstance.ts :

if (existingRegistration) { // When the Service Worker is registered, update it and return the reference. return existingRegistration.update().then(() => { return [ getWorkerByRegistration( existingRegistration, absoluteWorkerUrl, findWorker, ), existingRegistration, ] }) }

I'm asking, why do we need to call update() on existingRegistration before returning worker instance if worker is active ?

Expected behavior

Suggestion:

  • Add an option in StartOptions interface to bypass update if not needed.
  • Try update() but catch error and return worker instance from registration if active.
@lazpit lazpit added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:browser Related to MSW running in a browser labels Jan 30, 2024
@lazpit
Copy link
Author

lazpit commented Feb 12, 2024

This error seems to occur when there is a "no-cache" header when fetching service-worker.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:browser Related to MSW running in a browser
Projects
None yet
Development

No branches or pull requests

1 participant