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

Perform worker update in parallel #2310

Closed
4 tasks done
kettanaito opened this issue Oct 10, 2024 · 1 comment · Fixed by #2311
Closed
4 tasks done

Perform worker update in parallel #2310

kettanaito opened this issue Oct 10, 2024 · 1 comment · Fixed by #2311
Assignees
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. performance scope:browser Related to MSW running in a browser

Comments

@kettanaito
Copy link
Member

kettanaito commented Oct 10, 2024

Prerequisites

Environment check

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

Browsers

No response

Reproduction repository

Any example

Reproduction steps

  1. Have a context that activates MSW.
  2. Have another MSW activation in the same context.

Current behavior

When MSW finds a matching registration and attempts to reuse it, it first updates the worker. That is done to make sure that the existing worker registration is up-to-date. For example, if you are registering a worker that doesn't match the existing worker (i.e. the script has changed due to the MSW version change), the existing worker will be marked as redundant.

// When the Service Worker is registered, update it and return the reference.
return existingRegistration.update().then(() => {

The problem is that .update() takes time. It needs to fetch the worker script, evaluate it byte-by-byte, comparing the old and the new scripts. That's a potential overhead that MSW doesn't have to await.

Expected behavior

Update is scheduled to run in the background. MSW resolves with the existing worker registration immediately.

@kettanaito kettanaito added bug Something isn't working scope:browser Related to MSW running in a browser needs:triage Issues that have not been investigated yet. performance labels Oct 10, 2024
@kettanaito kettanaito self-assigned this Oct 10, 2024
@kettanaito
Copy link
Member Author

Released: v2.4.10 🎉

This has been released in v2.4.10!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. performance scope:browser Related to MSW running in a browser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant