Skip to content

Commit 2b925b4

Browse files
authored
fix: replace navigating.current.x with navigating.x (#13174)
* fix: replace navigating.current.x with navigating.x * ugh * regenerate
1 parent 899ff3f commit 2b925b4

File tree

7 files changed

+73
-20
lines changed

7 files changed

+73
-20
lines changed

.changeset/neat-buses-collect.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: replace `navigating.current.<x>` with `navigating.<x>`

packages/kit/src/runtime/app/state/client.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,39 @@ export const page = {
5959
};
6060

6161
/**
62-
* An object with a reactive `current` property.
63-
* When navigation starts, `current` is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
64-
* When navigation finishes, `current` reverts to `null`.
65-
*
66-
* On the server, this value can only be read during rendering. In the browser, it can be read at any time.
67-
* @type {{ get current(): import('@sveltejs/kit').Navigation | null; }}
62+
* An object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
63+
* Values are `null` when no navigation is occurring, or during server rendering.
64+
* @type {import('@sveltejs/kit').Navigation | { from: null, to: null, type: null, willUnload: null, delta: null, complete: null }}
6865
*/
66+
// @ts-expect-error
6967
export const navigating = {
70-
get current() {
71-
return _navigating.current;
68+
get from() {
69+
return _navigating.current ? _navigating.current.from : null;
70+
},
71+
get to() {
72+
return _navigating.current ? _navigating.current.to : null;
73+
},
74+
get type() {
75+
return _navigating.current ? _navigating.current.type : null;
76+
},
77+
get willUnload() {
78+
return _navigating.current ? _navigating.current.willUnload : null;
79+
},
80+
get delta() {
81+
return _navigating.current ? _navigating.current.delta : null;
82+
},
83+
get complete() {
84+
return _navigating.current ? _navigating.current.complete : null;
7285
}
7386
};
7487

88+
Object.defineProperty(navigating, 'current', {
89+
get() {
90+
// between 2.12.0 and 2.12.1 `navigating.current` existed
91+
throw new Error('Replace navigating.current.<prop> with navigating.<prop>');
92+
}
93+
});
94+
7595
/**
7696
* 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.
7797
* @type {{ get current(): boolean; check(): Promise<boolean>; }}

packages/kit/src/runtime/app/state/server.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ export const page = {
4545
};
4646

4747
export const navigating = {
48-
get current() {
49-
return (__SVELTEKIT_DEV__ ? context_dev('navigating.current') : context()).navigating;
50-
}
48+
from: null,
49+
to: null,
50+
type: null,
51+
willUnload: null,
52+
delta: null,
53+
complete: null
5154
};
5255

5356
export const updated = {

packages/kit/test/apps/basics/src/routes/state/navigating/+layout.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
</nav>
1010

1111
<div id="nav-status">
12-
{#if navigating.current}
12+
{#if navigating.to}
1313
<!-- prettier-ignore -->
1414
<p id="navigating">
15-
navigating from {navigating.current.from.url.pathname} to {navigating.current.to.url.pathname} ({navigating.current.type})
15+
navigating from {navigating.from.url.pathname} to {navigating.to.url.pathname} ({navigating.type})
1616
</p>
1717
{:else}
1818
<p id="not-navigating">not currently navigating</p>

packages/kit/types/index.d.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,14 +2293,16 @@ declare module '$app/state' {
22932293
* */
22942294
export const page: import("@sveltejs/kit").Page;
22952295
/**
2296-
* An object with a reactive `current` property.
2297-
* When navigation starts, `current` is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
2298-
* When navigation finishes, `current` reverts to `null`.
2299-
*
2300-
* On the server, this value can only be read during rendering. In the browser, it can be read at any time.
2296+
* An object representing an in-progress navigation, with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
2297+
* Values are `null` when no navigation is occurring, or during server rendering.
23012298
* */
2302-
export const navigating: {
2303-
get current(): import("@sveltejs/kit").Navigation | null;
2299+
export const navigating: import("@sveltejs/kit").Navigation | {
2300+
from: null;
2301+
to: null;
2302+
type: null;
2303+
willUnload: null;
2304+
delta: null;
2305+
complete: null;
23042306
};
23052307
/**
23062308
* 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.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import { page, navigating } from '$app/state';
3+
4+
let { children } = $props();
5+
6+
$inspect(navigating.to);
7+
</script>
8+
9+
<nav>
10+
<a href="/">/</a>
11+
<a href="/a">/a</a>
12+
<a href="/b">/b</a>
13+
<a href="/c">/c</a>
14+
<a href="/d">/d</a>
15+
<a href="/e">/e</a>
16+
</nav>
17+
18+
{@render children()}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import { page } from '$app/state';
3+
</script>
4+
5+
<h1>{page.params.slug}</h1>

0 commit comments

Comments
 (0)