Skip to content

Commit ece3906

Browse files
fix: detect build-emitted assets in prerenderer fetch (#12201)
* prerender emitted assets * mend * simplify * simplify * Update .changeset/chilled-humans-roll.md --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Rich Harris <[email protected]>
1 parent dbf0f05 commit ece3906

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

.changeset/chilled-humans-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": patch
3+
---
4+
5+
fix: `fetch` imported assets during prerender

packages/kit/src/core/postbuild/prerender.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
242242
const filepath = saved.get(file);
243243
if (filepath) return readFileSync(filepath);
244244

245+
// Static assets emitted during build
246+
if (file.startsWith(config.appDir)) {
247+
return readFileSync(`${out}/server/${file}`);
248+
}
249+
245250
// stuff in `static`
246251
return readFileSync(join(config.files.assets, file));
247252
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @ts-ignore
2+
import url from './message.csv?url';
3+
4+
export async function load({ fetch }) {
5+
const response = await fetch(url);
6+
const message = await response.text();
7+
return { message };
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
const { data } = $props();
3+
</script>
4+
5+
<p>{data.message}</p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello from message.csv

packages/kit/test/prerendering/paths-base/test/tests.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ test('prerenders /path-base/assets', () => {
2929
const content = read('assets.html');
3030
assert.match(content, /<img[^>]+src="\/path-base\//u);
3131
});
32+
33+
test('prerenders /path-base/assets/emitted', () => {
34+
const content = read('assets/emitted.html');
35+
assert.ok(content.includes('<p>hello from message.csv'));
36+
});

0 commit comments

Comments
 (0)