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: clone Response before logging #1662

Merged
merged 1 commit into from
Jul 20, 2023
Merged

Conversation

kettanaito
Copy link
Member

Changes

  • The IsomorphicResponse -> Response construction for the fallback mode (in-browser only) now uses the standard Response class (every response can now be cloned).
  • Clone the response in the serializeResponse before reading its body.
  • Also clone the response immediately on the regular worker response handling.

@codesandbox-ci
Copy link

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 37e73c8:

Sandbox Source
MSW React Configuration

ok: response.status >= 200 && response.status < 300,
url: '',
type: 'default',
return new Response(response.body, {
Copy link
Member Author

Choose a reason for hiding this comment

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

It scares me a bit why the previous logic was contrived here. This function is only called in the fallback mode, which is browser-only if the Service Worker API is not available (old browsers, locally-served apps). Since we are in the browser, we can rely on Response, we always could.

@kettanaito kettanaito merged commit daa04af into main Jul 20, 2023
10 checks passed
@kettanaito kettanaito deleted the fix/response-stream-already-read branch July 20, 2023 10:17
@kettanaito
Copy link
Member Author

Released: v1.2.3 🎉

This has been released in v1.2.3!

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
Development

Successfully merging this pull request may close these issues.

Consistent "TypeError: Failed to execute 'text' on 'Response': body stream already read" since v1.2.2
2 participants