Skip to content

Commit

Permalink
fetch 'body': don't try to tee() more than once
Browse files Browse the repository at this point in the history
  • Loading branch information
ximus committed Jan 13, 2024
1 parent 09ac6b4 commit 2e7976f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/server/page/load_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
}
}

/** @type {ReadableStream<Uint8Array>} */
let teed_body;

const proxy = new Proxy(response, {
get(response, key, _receiver) {
/**
Expand Down Expand Up @@ -313,6 +316,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
}

if (key === 'body') {
if (teed_body) return teed_body;
const body = response.body;
if (!body) return body;
const [a, b] = body.tee();
Expand All @@ -339,7 +343,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
}
}
reader.read().then(buffer_to_fetched);
return b;
return (teed_body = b);
}

if (key === 'arrayBuffer') {
Expand Down

0 comments on commit 2e7976f

Please sign in to comment.