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

fix: put forking behind `experimental.forkPreloads`
27 changes: 26 additions & 1 deletion packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const get_defaults = (prefix = '') => ({
experimental: {
tracing: { server: false },
instrumentation: { server: false },
remoteFunctions: false
remoteFunctions: false,
forkPreloads: false
},
files: {
src: join(prefix, 'src'),
Expand Down Expand Up @@ -479,6 +480,30 @@ test('errors on invalid tracing values', () => {
}, /^config\.kit\.experimental\.tracing\.server should be true or false, if specified$/);
});

test('errors on invalid forkPreloads values', () => {
assert.throws(() => {
validate_config({
kit: {
experimental: {
// @ts-expect-error - given value expected to throw
forkPreloads: 'true'
}
}
});
}, /^config\.kit\.experimental\.forkPreloads should be true or false, if specified$/);

assert.throws(() => {
validate_config({
kit: {
experimental: {
// @ts-expect-error - given value expected to throw
forkPreloads: 1
}
}
});
}, /^config\.kit\.experimental\.forkPreloads should be true or false, if specified$/);
});

test('uses src prefix for other kit.files options', async () => {
const cwd = join(__dirname, 'fixtures/custom-src');

Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ const options = object(
instrumentation: object({
server: boolean(false)
}),
remoteFunctions: boolean(false)
remoteFunctions: boolean(false),
forkPreloads: boolean(false)
}),

files: object({
Expand Down
6 changes: 6 additions & 0 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ export interface KitConfig {
* @default false
*/
remoteFunctions?: boolean;

/**
* Whether to enable the experimental forked preloading feature using Svelte's fork API.
* @default false
*/
forkPreloads?: boolean;
};
/**
* Where to find various files within your project.
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ async function kit({ svelte_config }) {
__SVELTEKIT_APP_DIR__: s(kit.appDir),
__SVELTEKIT_EMBEDDED__: s(kit.embedded),
__SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: s(kit.experimental.remoteFunctions),
__SVELTEKIT_FORK_PRELOADS__: s(kit.experimental.forkPreloads),
__SVELTEKIT_PATHS_ASSETS__: s(kit.paths.assets),
__SVELTEKIT_PATHS_BASE__: s(kit.paths.base),
__SVELTEKIT_PATHS_RELATIVE__: s(kit.paths.relative),
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ async function _preload_data(intent) {
fork: null
};

if (svelte.fork) {
if (__SVELTEKIT_FORK_PRELOADS__ && svelte.fork) {
const lc = load_cache;

lc.fork = lc.promise.then((result) => {
Expand All @@ -545,7 +545,7 @@ async function _preload_data(intent) {
update(result.props.page);
});
} catch {
// if it errors, it's because the experimental flag isn't enabled
// if it errors, it's because the experimental flag isn't enabled in Svelte
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/types/global-private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ declare global {
const __SVELTEKIT_SERVER_TRACING_ENABLED__: boolean;
/** true if corresponding config option is set to true */
const __SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: boolean;
/** True if `config.kit.experimental.forkPreloads` is `true` */
const __SVELTEKIT_FORK_PRELOADS__: boolean;
/** True if `config.kit.router.resolution === 'client'` */
const __SVELTEKIT_CLIENT_ROUTING__: boolean;
/** True if `config.kit.router.type === 'hash'` */
Expand Down
6 changes: 6 additions & 0 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,12 @@ declare module '@sveltejs/kit' {
* @default false
*/
remoteFunctions?: boolean;

/**
* Whether to enable the experimental forked preloading feature using Svelte's fork API.
* @default false
*/
forkPreloads?: boolean;
};
/**
* Where to find various files within your project.
Expand Down
Loading