Server fetch ignore init if first param is a Request
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
normalize_fetch_input ignores init if info is a Request:
/**
* @param {RequestInfo | URL} info
* @param {RequestInit | undefined} init
* @param {URL} url
*/
function normalize_fetch_input(info, init, url) {
if (info instanceof Request) {
return info;
}
return new Request(typeof info === 'string' ? new URL(info, url) : info, init);
}
https://github.com/sveltejs/kit/blob/main/packages/kit/src/runtime/server/fetch.js#L188
When init is ignored, the server fetch function doesn't behave like it does in the browser.
Reproduction
For example:
export const load: PageServerLoad = async ({ fetch }) => {
const req = new Request(someUrl);
const init = { headers: { 'Authorization': 'some-token } };
// this ignores init
const response = await fetch(req, init);
// this uses init with the headers
const response2 = await fetch(new Request(req, init));
}
In the browser each fetch call would behave the same. mdn has a similar example - https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#passing_options_into_both_request_and_fetch
Logs
System Info
npmPackages:
@sveltejs/adapter-auto: ^6.1.0 => 6.1.1
@sveltejs/adapter-node: ^5.4.0 => 5.4.0
@sveltejs/kit: ^2.43.2 => 2.50.0
@sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1
svelte: ^5.39.5 => 5.39.10
vite: 7.1.11 => 7.1.11
Severity
annoyance
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/kit/src/runtime/server/fetch.js at normalize_fetch_input and compare its Request handling with the browser Fetch API behavior described in the issue. Reproduce the Request-plus-init case, then verify that server fetch applies the init options consistently with the equivalent new Request(req, init) example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100