Skip to content

Commit

Permalink
fix: account for server-emitted assets when prerendering (#9349)
Browse files Browse the repository at this point in the history
fixes #9146
  • Loading branch information
Rich-Harris committed Mar 8, 2023
1 parent b575287 commit daad7e4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/polite-buckets-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: account for server-emitted assets when prerenering
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import src from './image.jpg';

export function load() {
return {
src
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let data;
</script>

<img src={data.src} alt="birb" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion packages/kit/src/core/postbuild/prerender.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, writeFileSync } from 'node:fs';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { installPolyfills } from '../../exports/node/polyfills.js';
Expand Down Expand Up @@ -144,6 +144,13 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) {
}

const files = new Set(walk(`${out}/client`).map(posixify));

const immutable = `${config.appDir}/immutable`;
if (existsSync(`${out}/server/${immutable}`)) {
for (const file of walk(`${out}/server/${immutable}`)) {
files.add(posixify(`${config.appDir}/immutable/${file}`));
}
}
const seen = new Set();
const written = new Set();

Expand Down

0 comments on commit daad7e4

Please sign in to comment.