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

fix: ensure environment setup is in its own chunk
4 changes: 4 additions & 0 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,13 @@ async function kit({ svelte_config }) {
config.build.rollupOptions.output = {
...config.build.rollupOptions.output,
manualChunks(id, meta) {
// Prevent core runtime and env from ending up in a remote chunk, which could break because of initialization order
if (id === `${runtime_directory}/app/server/index.js`) {
return 'app-server';
}
if (id === `${runtime_directory}/shared-server.js`) {
return 'app-shared-server';
}

// Check if this is a *.remote.ts file
if (svelte_config.kit.moduleExtensions.some((ext) => id.endsWith(`.remote${ext}`))) {
Expand Down
5 changes: 4 additions & 1 deletion packages/kit/test/apps/basics/src/routes/remote/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
set_count_server_set,
resolve_deferreds
} from './query-command.remote.js';
import { q } from './accessing-env.remote';

let { data } = $props();

let command_result = $state(null);
let release;

// we just want it not to be treeshaken away
q;

const count = browser ? get_count() : null; // so that we get a remote request in the browser
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { query } from '$app/server';
import { env } from '$env/dynamic/private';
import { env as public_env } from '$env/dynamic/public';

if (!env.PRIVATE_DYNAMIC || !public_env.PUBLIC_DYNAMIC) {
// This checks that dynamic env vars are available when prerendering remote functions
// https://github.com/sveltejs/kit/pull/14219
// and are not in the same chunk as this one
// https://github.com/sveltejs/kit/issues/14439
throw new Error('Dynamic environment variables are not set up correctly');
}

// placeholder query that needs to be imported/used elsewhere so that bundling/chunking would include env setup if not setup correctly
export const q = query(() => {});