-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inline Response.arrayBuffer inside load functions during ssr (#…
…10535) * add tests * encode arraybuffer with b64 * add arrayBuffer to doc * changeset * removed dependency * big endian * format * Update packages/kit/src/runtime/server/page/load_data.js * Update .changeset/fifty-tigers-turn.md --------- Co-authored-by: Rich Harris <hello@rich-harris.dev>
- Loading branch information
1 parent
d7ba3bf
commit 594568e
Showing
10 changed files
with
167 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': minor | ||
--- | ||
|
||
feat: inline `response.arrayBuffer()` during ssr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/kit/test/apps/basics/src/routes/load/fetch-arraybuffer-b64/+page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export async function load({ fetch }) { | ||
const res = await fetch('/load/fetch-arraybuffer-b64/data'); | ||
|
||
const l = await fetch('/load/fetch-arraybuffer-b64/data', { | ||
body: Uint8Array.from(Array(256).fill(0), (_, i) => i), | ||
method: 'POST' | ||
}); | ||
|
||
return { | ||
data: res.arrayBuffer(), | ||
data_long: l.arrayBuffer() | ||
}; | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/kit/test/apps/basics/src/routes/load/fetch-arraybuffer-b64/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script> | ||
export let data; | ||
$: arr = [...new Uint8Array(data.data)]; | ||
let ok = 'Ok'; | ||
$: { | ||
const p = new Uint8Array(data.data_long); | ||
ok = p.length === 256 ? 'Ok' : 'Wrong length'; | ||
if (p.length === 256) { | ||
for (let i = 0; i < p.length; i++) { | ||
if (p[i] !== i) { | ||
ok = `Expected ${i} but got ${p[i]}`; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<span class="test-content">{JSON.stringify(arr)}</span> | ||
|
||
<br /> | ||
|
||
{ok} | ||
<span style="word-wrap: break-word;"> | ||
{JSON.stringify([...new Uint8Array(data.data_long)])} | ||
</span> |
7 changes: 7 additions & 0 deletions
7
packages/kit/test/apps/basics/src/routes/load/fetch-arraybuffer-b64/data/+server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const GET = () => { | ||
return new Response(new Uint8Array([1, 2, 3, 4])); | ||
}; | ||
|
||
export const POST = async ({ request }) => { | ||
return new Response(await request.arrayBuffer()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters