GithubHelp home page GithubHelp logo

Comments (9)

annevk avatar annevk commented on June 14, 2024

I see two solutions I like a bit better as I don't really care for XMLHttpRequest:

  • We use a more limited form of BodyInit for XMLHttpRequest
  • We throw when you pass a ReadableStream and the synchronous flag is set.

Note that upload streams in general still have issues that are being sorted out in the Fetch repository.

cc @yutakahirano

from xhr.

yutakahirano avatar yutakahirano commented on June 14, 2024

So in other words, in order to transmit the request body of the fetch, we need to read from the stream, which, at least if the body is a user provided stream, will require running code on an event-loop. It that event-loop is the same that is currently blocking on the fetch call as part of a sync XHR, it appears to be an actual deadlock.

I'm confused by this paragraph, as for XHR there is no user provided stream.

from xhr.

annevk avatar annevk commented on June 14, 2024

@yutakahirano there is, send() takes BodyInit which consists of ReadableStream among other things.

from xhr.

yutakahirano avatar yutakahirano commented on June 14, 2024

Oh sorry I missed that, thank you. Then I prefer removing that functionality from XHR. I'm not sure if which of throwing or ignoring is better.

from xhr.

gterzian avatar gterzian commented on June 14, 2024

Makes sense, strictly speaking even in the other BodyInit cases those objects are extracted into a stream, and those could be said to be fully "native" streams where reading chunks would not require calling into JS.

from xhr.

gterzian avatar gterzian commented on June 14, 2024

How about we remove the functionality, and then implementations can still warn in their own way if needed about use of a deprecated feature?

I can open a PR...

from xhr.

gterzian avatar gterzian commented on June 14, 2024

On the other hand, returning an error in the stream case allows us to still use BodyInit, versus adding a new IDL like XhrBodyInit that would not include a stream.

But send doesn't return an error now, so that's maybe another complication.

We could also define send like:

void send(optional (Document or Blob or BufferSource or FormData or URLSearchParams or USVString)? body = null);

The algorithm would still "work", since "Otherwise, set request body and extractedContentType to the result of extracting body" would work "as is" I think.

from xhr.

annevk avatar annevk commented on June 14, 2024

Thinking about it more I suspect implementations don't support this today and what happens is that ReadableStream gets stringified. That's acceptable to me.

I would suggest we define XMLHttpRequestBodyInit in Fetch and define BodyInit as (ReadableStream or XMLHttpRequestBodyInit). And make XMLHttpRequest use (Document or XMLHttpRequestBodyInit).

ReadableStream will stringify in IDL land and then be treated as a string in XMLHttpRequest as a result.

If you're willing to tackle this @gterzian that'd be great!

from xhr.

gterzian avatar gterzian commented on June 14, 2024

Ok I'll take it on, starting with the change in Fetch then.

from xhr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.