-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
regression: Response does not accept a async-iterator anymore #49551
Comments
cc @Trott |
Q (coming here from the citgm PR with zero background 😅): what is the expected behavior of that code? In browser, |
@mcollina maybe your example is wrong, but you can't pass AsyncIterables as response bodies directly. The only valid streaming BodyInit is ReadableStream. |
Have you got a spec reference @lucacasonato? @KhafraDev wdyt? |
None of those types are IDL types that can be created directly from an async iterable / async iterator. Your example should be |
Thanks for the explanation! @KhafraDev should we change this or leave as-is for backward compat with node-fetch? |
This was added so fetch could support node streams. We should definitely keep it. |
doesn't seem to be great for interoperable code between runtimes and browsers. that said, how would users know about this? the docs are just mentioning
I haven't looked into this, but doesn't node provide a |
@KhafraDev Fetch can support node streams through It is obviously not my call to make, but I want to advise you that keeping this behaviour is a dangerous hazard for future spec compatibility for Node.js. This is because if If Node did not accept arbitrary async iterables, but rather only branded node streams in the BodyInit position, your usecase would be resolved without exposing Node to this dangerous future compatibility hazard. I think this would be a much safer alternative you could consider. |
It's mentioned in the undici docs, there probably should be more extensive docs for fetch in node core. I agree with you and it wasn't my idea to support arbitrary async iterables, but I don't think it's as harmful as it's being made out to be. We've already implemented breaking changes that were made in the spec that broke users, so it would be the same here. For example, when a change was introduced that removes Authorization headers from cross-origin redirects or when a I couldn't find past discussions but @ronag added it so he might be able to give a better answer. |
It was added so that node-fetch could be more easily be replaced with native fetch. The value was deemed high and any possible negative side effects were considered negligible. Not supporting it is an unnecessary breaking change. |
Ref: whatwg/fetch#1291 |
Folks now think this is standard behavior and are opening issues on the Deno repo about us not supporting this. This is why you don't do random willy nilly spec extensions folks 🙄 |
Deno doesn't support forbidden headers, is that not also a "willy nilly spec extension"? Node supported them at one point, and removed it to match Deno's behavior (and we've had multiple issues regarding it). |
We discussed that issue at length in WinterCG. Also it was a spec extension because it obviously was never going to make sense in browsers so the only path forward was a spec extension. It was as such not "willy nilly" |
deno's handling of forbidden headers existed before wintercg's inception. If not that, Deno had special handling for set-cookie headers before getSetCookie. I don't see these as any different from node/undici supporting async iterable bodies. |
@KhafraDev Sorry, I was a bit tired yesterday when I wrote this message and it wasn't very nice. I apologize for my wording - I shouldn't have been so confrontational. The extensions that we made to the spec were all born out of necessity - both of the cases you mentioned where not solvable without spec extensions. We also put in significant effort in either case to align with other runtimes, and coordinate upstreaming the extensions where possible. In the case of the forbidden headers, we had no path to upstreaming, and so we did the next best thing which was to deviate from spec, but to align to other existing implementations (Cloudflare Workers). In the case of I was just a bit annoyed at the async iterables as body deviation because it was not at all driven by spec necessity (ie no other way to do this), because trivial workarounds are possible. For example, using Anyway, I don't want to argue with you about this, I just wanted to show that this creates ecosystem confusion and portability hazards that may not have been considered when originally shipping this, and may be a good trigger to re-evaluate whether this deviation should exist. I'd be happy to talk this through thoroughly at the next WinterCG call if you are interested. |
Another user was confused, thinking this was standard behaviour: withastro/astro#10495 (comment). I want to once again suggest that you unship this behaviour as long as there is no written specification for the behaviour, or consensus for including this behaviour in the Fetch spec via WHATWG. I want to reiterate that users relying on this behaviour have a trivial workaround using |
This specific issue can be closed, I think, because we ship the non-spec compliant behavior. I think we should keep shipping it as it massively simplifies interoperability in a performant way. The proposed workaround is significantly slower because creating WHATWG streams is so much slower for us. |
I disagree strongly @mcollina. This significantly hurts interop with code that should run in both browsers, Deno and Node. You can special case It is very unfortunate that instead of speeding up |
I think what @mcollina means is that another issue should be opened wrt the interop question. The regression that this issue was about isn't here anymore. |
I was wrong about the performance impact, as right now there is no difference. Currently, we just call
I think it's way too late to remove this for Node.js. This is definitely a breaking change and it would cause significant breakage for v18 and v20 users. As @targos said, this issue was about a regression for something that has already been there for quite some time and it regressed. @lucacasonato feel free to open a fresh issue about this, here or in the undici repo. My 2 cents is that the best solution for this is try to standardize this behavior and re-assess. |
Just want to ping here again that Node shipping this without standards discussion is super frustrating, because it turns out standardization of this feature is not that easy because Node was not following prior precedent in ECMAScript and Web APIs by not handling |
#48395 which shipped in Node v20.6.0 broke part of the
fetch()
spec and was caught by CITGM with some of the undici test failing everywhere.This stopped working:
I'm shipping a fix in undici in nodejs/undici#2251.
Ref. nodejs/citgm#959
(FWIW we should have caught this before release)
The text was updated successfully, but these errors were encountered: