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/breezy-walls-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

only prerender a given dependency once
16 changes: 15 additions & 1 deletion packages/kit/src/core/prerender/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,20 @@ export async function prerender() {
/** @type {import('types').SSRManifest} */
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;

/** @type {Map<string, string>} */
const saved = new Map();

override({
building: true,
paths: config.paths,
read: (file) => readFileSync(join(config.files.assets, file))
read: (file) => {
// stuff we just wrote
const filepath = saved.get(file);
if (filepath) return readFileSync(filepath);

// stuff in `static`
return readFileSync(join(config.files.assets, file));
}
});

const server = new Server(manifest);
Expand Down Expand Up @@ -222,6 +232,7 @@ export async function prerender() {
}

const body = result.body ?? new Uint8Array(await result.response.arrayBuffer());

save(
'dependencies',
result.response,
Expand Down Expand Up @@ -351,6 +362,9 @@ export async function prerender() {
} else if (response_type !== OK) {
handle_http_error({ status: response.status, path: decoded, referrer, referenceType });
}

manifest.assets.add(file);
saved.set(file, dest);
}

for (const route of manifest._.routes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('@sveltejs/kit').Load} */
export async function load({ fetch }) {
const url = '/fetch-endpoint/not-buffered.json';
const res = await fetch(url);

return {
headers: res.headers
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
/** @type {import('./$types').PageData} */
export let data;
</script>

<h1>content-type: {data.headers.get('content-type')}</h1>
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { json } from '@sveltejs/kit';

let called = false;

export async function GET() {
if (called) throw new Error('should only be called once');
called = true;

return json({ answer: 42 });
}