Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thick-gorillas-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: page load `fetch()` now accepts the same input types for the body as the native fetch function
11 changes: 0 additions & 11 deletions packages/kit/src/runtime/server/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
return async (info, init) => {
const original_request = normalize_fetch_input(info, init, event.url);

const request_body = init?.body;

// some runtimes (e.g. Cloudflare) error if you access `request.mode`,
// annoyingly, so we need to read the value from the `init` object instead
let mode = (info instanceof Request ? info.mode : init?.mode) ?? 'cors';
Expand Down Expand Up @@ -111,15 +109,6 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
}
}

if (request_body && typeof request_body !== 'string' && !ArrayBuffer.isView(request_body)) {
// TODO is this still necessary? we just bail out below
// per https://developer.mozilla.org/en-US/docs/Web/API/Request/Request, this can be a
// Blob, BufferSource, FormData, URLSearchParams, USVString, or ReadableStream object.
// non-string bodies are irksome to deal with, but luckily aren't particularly useful
// in this context anyway, so we take the easy route and ban them
throw new Error('Request body must be a string or TypedArray');
}

if (!request.headers.has('accept')) {
request.headers.set('accept', '*/*');
}
Expand Down