diff --git a/.changeset/odd-mirrors-fold.md b/.changeset/odd-mirrors-fold.md new file mode 100644 index 000000000000..c497dd93546c --- /dev/null +++ b/.changeset/odd-mirrors-fold.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: correctly resolve `$app/state` on the server with Vite 5 diff --git a/packages/kit/scripts/generate-dts.js b/packages/kit/scripts/generate-dts.js index c10dad802433..e8579ec59054 100644 --- a/packages/kit/scripts/generate-dts.js +++ b/packages/kit/scripts/generate-dts.js @@ -14,7 +14,7 @@ await createBundle({ '$app/navigation': 'src/runtime/app/navigation.js', '$app/paths': 'src/runtime/app/paths/types.d.ts', '$app/server': 'src/runtime/app/server/index.js', - '$app/state': 'src/runtime/app/state/client.js', + '$app/state': 'src/runtime/app/state/index.js', '$app/stores': 'src/runtime/app/stores.js' }, include: ['src'] diff --git a/packages/kit/src/runtime/app/state/client.js b/packages/kit/src/runtime/app/state/client.js index e722819451ec..7a276d0d9512 100644 --- a/packages/kit/src/runtime/app/state/client.js +++ b/packages/kit/src/runtime/app/state/client.js @@ -5,32 +5,6 @@ import { } from '../../client/state.svelte.js'; import { stores } from '../../client/client.js'; -/** - * A reactive object with information about the current page, serving several use cases: - * - retrieving the combined `data` of all pages/layouts anywhere in your component tree (also see [loading data](https://svelte.dev/docs/kit/load)) - * - retrieving the current value of the `form` prop anywhere in your component tree (also see [form actions](https://svelte.dev/docs/kit/form-actions)) - * - retrieving the page state that was set through `goto`, `pushState` or `replaceState` (also see [goto](https://svelte.dev/docs/kit/$app-navigation#goto) and [shallow routing](https://svelte.dev/docs/kit/shallow-routing)) - * - retrieving metadata such as the URL you're on, the current route and its parameters, and whether or not there was an error - * - * ```svelte - * - * - * - *
Currently at {page.url.pathname}
- * - * {#if page.error} - * Problem detected - * {:else} - * All systems operational - * {/if} - * ``` - * - * On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time. - * - * @type {import('@sveltejs/kit').Page} - */ export const page = { get data() { return _page.data; @@ -58,12 +32,6 @@ export const page = { } }; -/** - * An object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties. - * Values are `null` when no navigation is occurring, or during server rendering. - * @type {import('@sveltejs/kit').Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }} - */ -// @ts-expect-error export const navigating = { get from() { return _navigating.current ? _navigating.current.from : null; @@ -92,10 +60,6 @@ Object.defineProperty(navigating, 'current', { } }); -/** - * A reactive value that's initially `false`. If [`version.pollInterval`](https://svelte.dev/docs/kit/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update `current` to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling. - * @type {{ get current(): boolean; check(): PromiseCurrently at {page.url.pathname}
+ * + * {#if page.error} + * Problem detected + * {:else} + * All systems operational + * {/if} + * ``` + * + * On the server, values can only be read during rendering (in other words _not_ in e.g. `load` functions). In the browser, the values can be read at any time. + * + * @type {import('@sveltejs/kit').Page} + */ +export const page = BROWSER ? client_page : server_page; + +/** + * An object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties. + * Values are `null` when no navigation is occurring, or during server rendering. + * @type {import('@sveltejs/kit').Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }} + */ +// @ts-expect-error +export const navigating = BROWSER ? client_navigating : server_navigating; + +/** + * A reactive value that's initially `false`. If [`version.pollInterval`](https://svelte.dev/docs/kit/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update `current` to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling. + * @type {{ get current(): boolean; check(): Promise