Skip to content

Commit f67ba09

Browse files
KTiboweltigerchino
andauthored
fix: don't write temporary remote function bundle to disk (#14161)
* fix: don't write temporary remote function bundle to disk * add test * cleanup ts * Apply suggestion from @eltigerchino --------- Co-authored-by: Chew Tee Ming <[email protected]> Co-authored-by: Tee Ming <[email protected]>
1 parent 8d2f608 commit f67ba09

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.changeset/witty-kids-fail.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: avoid writing remote function bundle to disk when treeshaking prerendered queries

packages/kit/src/exports/vite/build/build_remote.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ export async function treeshake_prerendered_remotes(out, manifest_data, metadata
102102
input[prefix + remote.hash] = remote_file;
103103
}
104104

105-
const bundle = await vite.build({
105+
const bundle = /** @type {import('vite').Rollup.RollupOutput} */ (await vite.build({
106106
configFile: false,
107107
build: {
108+
write: false,
108109
ssr: true,
109110
rollupOptions: {
110111
external: (id) => {
@@ -114,11 +115,10 @@ export async function treeshake_prerendered_remotes(out, manifest_data, metadata
114115
input
115116
}
116117
}
117-
});
118+
}));
118119

119-
// @ts-expect-error TypeScript doesn't know what type `bundle` is
120120
for (const chunk of bundle.output) {
121-
if (chunk.name.startsWith(prefix)) {
121+
if (chunk.type === 'chunk' && chunk.name.startsWith(prefix)) {
122122
fs.writeFileSync(`${dir}/${chunk.fileName.slice(prefix.length)}`, chunk.code);
123123
}
124124
}

packages/kit/test/apps/basics/test/server.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,10 @@ test.describe('$app/environment', () => {
768768
expect(code).not.toContain('browser');
769769
});
770770
});
771+
772+
test.describe('remote functions', () => {
773+
test("doesn't write bundle to disk when treeshaking prerendered remote functions", () => {
774+
test.skip(!!process.env.DEV, 'skip when in dev mode');
775+
expect(fs.existsSync(path.join(root, 'dist'))).toBe(false);
776+
});
777+
});

0 commit comments

Comments
 (0)