From b35dcb0f606cde57159a4bb08cc9a25784cb5cbe Mon Sep 17 00:00:00 2001 From: Daniel Sticker Date: Sat, 31 Oct 2026 07:05:52 +0100 Subject: [PATCH 1/3] fix: set `navigation.from` to `null` on start without SSR --- .changeset/quiet-owls-enter.md | 5 +++++ packages/kit/src/runtime/client/client.js | 16 ++++++++++------ .../routes/no-ssr/after-navigate/+page.svelte | 4 ++++ .../apps/basics/test/playwright/client.test.js | 5 +++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 .changeset/quiet-owls-enter.md diff --git a/.changeset/quiet-owls-enter.md b/.changeset/quiet-owls-enter.md new file mode 100644 index 000000000000..1bb70a00e7d4 --- /dev/null +++ b/.changeset/quiet-owls-enter.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: set `navigation.from` to `null` in `afterNavigate` on start when SSR is disabled diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 45bd73155aaf..5e491ae8cc9e 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -3755,12 +3755,16 @@ function create_navigation( /** @type {(Navigation | AfterNavigate) & { type: T }} */ const navigation = /** @type {any} */ ({ - from: { - params: current.params, - route: { id: current.route?.id ?? null }, - url: current.url, - scroll: scroll_state() - }, + // the app's first navigation has no page to come from + from: + type === 'enter' + ? null + : { + params: current.params, + route: { id: current.route?.id ?? null }, + url: current.url, + scroll: scroll_state() + }, to: url && { params: target ? target.params : (intent?.params ?? null), route: { id: target ? (target.route?.id ?? null) : (intent?.route?.id ?? null) }, diff --git a/packages/kit/test/apps/basics/src/routes/no-ssr/after-navigate/+page.svelte b/packages/kit/test/apps/basics/src/routes/no-ssr/after-navigate/+page.svelte index 0e99d8405c54..74c2b3348cdf 100644 --- a/packages/kit/test/apps/basics/src/routes/no-ssr/after-navigate/+page.svelte +++ b/packages/kit/test/apps/basics/src/routes/no-ssr/after-navigate/+page.svelte @@ -3,11 +3,15 @@ let count = 0; let type = ''; + /** @type {string | undefined} */ + let from; afterNavigate((event) => { count += 1; type = event.type; + from = JSON.stringify(event.from); });

{type.toString()} {count}

+

from: {from}

diff --git a/packages/kit/test/apps/basics/test/playwright/client.test.js b/packages/kit/test/apps/basics/test/playwright/client.test.js index de86366c610a..e6821a790e85 100644 --- a/packages/kit/test/apps/basics/test/playwright/client.test.js +++ b/packages/kit/test/apps/basics/test/playwright/client.test.js @@ -507,6 +507,11 @@ test.describe('SPA mode / no SSR', () => { await page.goto('/no-ssr/after-navigate'); await expect(page.locator('p')).toHaveText('enter 1'); }); + + test('afterNavigate has no origin on start', async ({ page }) => { + await page.goto('/no-ssr/after-navigate'); + await expect(page.locator('h2')).toHaveText('from: null'); + }); }); test.describe('$app/state', () => { From 6193de3ce6f62327b18b94331cec984f670fd4c3 Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Mon, 2 Nov 2026 03:14:08 +0800 Subject: [PATCH 2/3] narrow NavigationEnter from to null --- packages/kit/src/runtime/app/navigation/public.d.ts | 5 +++++ packages/kit/types/index.d.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/kit/src/runtime/app/navigation/public.d.ts b/packages/kit/src/runtime/app/navigation/public.d.ts index 325612ede306..b48ba67ae1e1 100644 --- a/packages/kit/src/runtime/app/navigation/public.d.ts +++ b/packages/kit/src/runtime/app/navigation/public.d.ts @@ -130,6 +130,11 @@ export interface NavigationBase { export interface NavigationEnter extends NavigationBase { type: 'enter'; + /** + * The app has just started, so there is no page it navigated from + */ + from: null; + /** * In case of a history back/forward navigation, the number of steps to go back/forward */ diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index c2b56afff601..e6fd6a895f47 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2649,6 +2649,11 @@ declare module '$app/navigation' { export interface NavigationEnter extends NavigationBase { type: 'enter'; + /** + * The app has just started, so there is no page it navigated from + */ + from: null; + /** * In case of a history back/forward navigation, the number of steps to go back/forward */ From f0051bfbc289d7244723b344061e03cf7be39826 Mon Sep 17 00:00:00 2001 From: Tee Ming Chew Date: Mon, 2 Nov 2026 03:28:43 +0800 Subject: [PATCH 3/3] chore: fix broken lockfile entry for protobufjs --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68860cfc2e07..a8a51a0f903a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6757,7 +6757,7 @@ snapshots: '@protobufjs/path': 1.1.2 '@protobufjs/pool': 1.1.0 '@protobufjs/utf8': 1.1.2 - '@types/node': 26.6.2 + '@types/node': 22.20.4 long: 5.3.2 punycode@2.3.1: {}