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(fetch): use structuredClone in clone body steps #1697

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

KhafraDev
Copy link
Member

Refs: #1666 (comment)

Enables the following WPTs (only Safari currently passes these tests, and the same 2 tests fail here):
https://wpt.fyi/results/fetch/api/response/response-clone.any.html?label=master&label=experimental&aligned&view=subtest


The spec does tell implementations to clone the stream, but you have to go down a few layers:

  1. Let « out1, out2 » be the result of teeing body’s stream.

  2. To tee a ReadableStream stream, return ? ReadableStreamTee(stream, true).

  3. ReadableStreamTee(stream, cloneForBranch2) will tee a given readable stream.

  4. The second argument, cloneForBranch2, governs whether or not the data from the original stream will be cloned (using HTML’s serializable objects framework) before appearing in the second of the returned branches.

@codecov-commenter
Copy link

Codecov Report

Base: 94.09% // Head: 94.08% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (6a1cc6e) compared to base (23fbc08).
Patch coverage: 91.66% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1697      +/-   ##
==========================================
- Coverage   94.09%   94.08%   -0.01%     
==========================================
  Files          53       53              
  Lines        4912     4923      +11     
==========================================
+ Hits         4622     4632      +10     
- Misses        290      291       +1     
Impacted Files Coverage Δ
lib/fetch/constants.js 96.29% <90.00%> (-3.71%) ⬇️
lib/fetch/body.js 95.81% <100.00%> (+0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 4b30d47 into nodejs:main Oct 13, 2022
@KhafraDev KhafraDev deleted the use-structured-clone-on-clone-body branch October 13, 2022 14:33
mrbbot added a commit to cloudflare/miniflare that referenced this pull request Dec 23, 2022
`5.11.0` includes nodejs/undici#1643.

There are some non-trivial changes required to upgrade to `5.14.0`:

- Since `undici@5.12.0` (nodejs/undici#1697),
  `structuredClone` is used on bodies, which may be byte streams.
  Due to a Node bug (nodejs/node#45955),
  readable byte streams cannot be transferred, breaking `fetch`.
- Since `undici@5.14.0` (nodejs/undici#1793),
  global `ReadableStream` and `TransformStream` are used if
  available. In the Vitest environment, (which modifies the global
  scope unlike Jest which runs tests in a VM context), if the
  `streams_enable_constructors` compatibility flag isn't enabled,
  `fetch` breaks as `ReadableStream`s can't be constructed.
metcoder95 pushed a commit to metcoder95/undici that referenced this pull request Dec 26, 2022
crysmags pushed a commit to crysmags/undici that referenced this pull request Feb 27, 2024
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.

4 participants