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

fix(setupServer): reference interceptors to support fast refresh #1299

Merged
merged 1 commit into from Jun 21, 2022

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jun 21, 2022

Changes

Since the interceptors for Node were instantiated in a different module, the HMR path never touched that module, resulting in those interceptor instances (and their listeners) persisting across hot reloads.

In this change, I'm passing the interceptors class references to the createSetupServer factory instead of accepting instances, and instantiating them in the setupServer call itself.

I've tested this on a fresh with-msw Next template and the issue about responding to the same request twice is resolved with this change.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 21, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1c6adc9:

Sandbox Source
MSW React Configuration

@kettanaito kettanaito force-pushed the fix/setup-server-interceptor-instances branch from 12cbb5d to f756ff3 Compare June 21, 2022 13:55
@kettanaito kettanaito force-pushed the fix/setup-server-interceptor-instances branch from f756ff3 to 1c6adc9 Compare June 21, 2022 13:57
@kettanaito kettanaito marked this pull request as ready for review June 21, 2022 13:57
@kettanaito kettanaito changed the title chore: instantiate interceptors in "createSetupServer" fix(setupServer): reference interceptors to support fast refresh Jun 21, 2022
@kettanaito kettanaito merged commit 72f0b25 into main Jun 21, 2022
@kettanaito kettanaito deleted the fix/setup-server-interceptor-instances branch June 21, 2022 14:41
@kettanaito
Copy link
Member Author

Released: v0.42.2 🎉

This has been released in v0.42.2!

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant