diff --git a/.changeset/neat-buses-collect.md b/.changeset/neat-buses-collect.md new file mode 100644 index 000000000000..84e194cf9c8d --- /dev/null +++ b/.changeset/neat-buses-collect.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: replace `navigating.current.` with `navigating.` diff --git a/packages/kit/src/runtime/app/state/client.js b/packages/kit/src/runtime/app/state/client.js index 47d806879a3f..e722819451ec 100644 --- a/packages/kit/src/runtime/app/state/client.js +++ b/packages/kit/src/runtime/app/state/client.js @@ -59,19 +59,39 @@ export const page = { }; /** - * An object with a reactive `current` property. - * When navigation starts, `current` is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties. - * When navigation finishes, `current` reverts to `null`. - * - * On the server, this value can only be read during rendering. In the browser, it can be read at any time. - * @type {{ get current(): import('@sveltejs/kit').Navigation | null; }} + * 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 current() { - return _navigating.current; + get from() { + return _navigating.current ? _navigating.current.from : null; + }, + get to() { + return _navigating.current ? _navigating.current.to : null; + }, + get type() { + return _navigating.current ? _navigating.current.type : null; + }, + get willUnload() { + return _navigating.current ? _navigating.current.willUnload : null; + }, + get delta() { + return _navigating.current ? _navigating.current.delta : null; + }, + get complete() { + return _navigating.current ? _navigating.current.complete : null; } }; +Object.defineProperty(navigating, 'current', { + get() { + // between 2.12.0 and 2.12.1 `navigating.current` existed + throw new Error('Replace navigating.current. with 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; }} diff --git a/packages/kit/src/runtime/app/state/server.js b/packages/kit/src/runtime/app/state/server.js index 770a85a739f8..ef60721a895e 100644 --- a/packages/kit/src/runtime/app/state/server.js +++ b/packages/kit/src/runtime/app/state/server.js @@ -45,9 +45,12 @@ export const page = { }; export const navigating = { - get current() { - return (__SVELTEKIT_DEV__ ? context_dev('navigating.current') : context()).navigating; - } + from: null, + to: null, + type: null, + willUnload: null, + delta: null, + complete: null }; export const updated = { diff --git a/packages/kit/test/apps/basics/src/routes/state/navigating/+layout.svelte b/packages/kit/test/apps/basics/src/routes/state/navigating/+layout.svelte index 833446e5be76..353e11936e82 100644 --- a/packages/kit/test/apps/basics/src/routes/state/navigating/+layout.svelte +++ b/packages/kit/test/apps/basics/src/routes/state/navigating/+layout.svelte @@ -9,10 +9,10 @@