fetch: body specified in RequestInit should take precedence

Open Beginner friendly
#142 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
api

Research direction

Start in crates/wasm-rquickjs/skeleton/src/builtin/http.js around line 73, where the fetch polyfill handles Request and RequestInit options. Reproduce the issue with the provided example and verify that the body passed directly to fetch takes precedence over the Request body.

Written by the indexing model from the issue text.

Description

While trying to wrap a library using wasm-rquickjs, I noticed the following incorrect behavior:

fetch(
  new Request('https://api.example.com', {
    method: 'POST',
    body: "original"
  }),
  {  body: "overriden" }
)

It should send body as "overriden", however the fetch polyfill currently sends "original" to the endpoint instead.

As per https://developer.mozilla.org/en-US/docs/Web/API/RequestInit

You can also construct a Request with a RequestInit, and pass the Request to a fetch() call along with another RequestInit. If you do this, and the same option is set in both places, then the value passed directly into fetch() is used.

Currently the way how wasm-rquickjs generates the project really helped a bunch, I could manually patch the http.js file here to take options.body if specified and the wrapped library started working correctly!

Dominant language
JavaScript
Stars
21
Forks
2
Avg merge
5d 2h
Merged PRs (30d)
21

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.