Skip to content

fix(BatchInterceptor): remove listeners between fast refresh#262

Closed
kettanaito wants to merge 2 commits intomainfrom
fix/fast-refresh
Closed

fix(BatchInterceptor): remove listeners between fast refresh#262
kettanaito wants to merge 2 commits intomainfrom
fix/fast-refresh

Conversation

@kettanaito
Copy link
Copy Markdown
Member

@kettanaito kettanaito commented Jun 15, 2022

Changes

  • Batch interceptor now prunes any existing listeners from the child interceptors. Such listeners may persist between fast refresh, causing the same request to be handled multiple times.
  • This adds support to run interceptors in modern apps that use HMR (Fast Refresh).

Roadmap

  • Ensure this also works for isolated interceptor usage (not batched).
  • Mention that you cannot attach listeners to interceptors if you then pass those interceptors to a BatchInterceptor. Always attach listeners to the batch interceptor. Maybe because of this accept class references and not instances?

* @see https://github.com/mswjs/msw/issues/1271
*/
for (const interceptor of this.interceptors) {
interceptor['emitter'].pruneListeners()
Copy link
Copy Markdown
Member Author

@kettanaito kettanaito Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha

Coupling internal _events pruning and .removeAllListeners() causes issues. Looks like we cannot remove the internal record all the time when the consumer removes listeners.

I'm adding a designated method that'd do both only in this particular scenario.

@kettanaito kettanaito marked this pull request as ready for review June 21, 2022 08:07
@kettanaito kettanaito deleted the fix/fast-refresh branch June 21, 2022 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(v.0.42) Error - Invariant Violation: Failed to respond request: the "request" event has already been responded to

1 participant