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

onUnhandledRequest drastically increasing execution time #37

Open
stephan-noel-primer opened this issue Jun 26, 2021 · 1 comment
Open
Labels
performance Improve performance of an existing feature

Comments

@stephan-noel-primer
Copy link

stephan-noel-primer commented Jun 26, 2021

Problem

Execution of visual tests on Chromatic goes from 3 minutes on average to around 18 minutes

Changing the following code:

 initializeWorker({
   onUnhandledRequest(req) {
     // Only some API requests should be mocked
     if (!req.url.href.startsWith(myapi(''))) {
       return;
     }
     console.error(
       'Found an unhandled %s request to %s',
       req.method,
       req.url.href,
     );

    throw new Error(
      'Unhandled request, please ensure you are mocking the correct endpoints',
    );
  },
});

to simply:

 initializeWorker();

fixed the issue.

I'm not sure if the problem is with this addon, with msw itself, or with how the integration is being done. If I want to workaround this and provide a fallback request handler to setupServer, I can't because there is no way to forward options to setupServer.

Version info:

msw-storybook-addon: 1.1.0
msw: 0.30.0:

@kettanaito
Copy link
Member

Hey, @stephan-noel-primer. Thank you for reaching out.

I can suspect the suggestions logic in MSW that can be the culprit here. Whenever there's an unhandled request, MSW looks up a list of suggested request handlers to account for typos and method/operation kind mismatches to improve the DX. This can be an expensive operation given a large number of handlers.

Your approach above is sensible. Perhaps we should consider disabling the handler suggestions as an option if that's proven to be the performance bottleneck. To debug this, I recommend forking MSW, removing the suggestions, linking it to the msw-storybook-addon and using its local built to see if there's any performance impact.

@yannbf yannbf added the performance Improve performance of an existing feature label Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Improve performance of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants