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.
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.
Prerequisites
Environment check
msw
versionBrowsers
No response
Reproduction repository
Any example
Reproduction steps
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.
https://github.com/mswjs/msw/blob/452686d27cc84c1a18262e9d0b18cf64b13aa71d/src/browser/setupWorker/start/utils/getWorkerInstance.ts#L39-L40
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.