Skip to content
Open
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/quiet-owls-enter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: set `navigation.from` to `null` in `afterNavigate` on start when SSR is disabled
16 changes: 10 additions & 6 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
</script>

<p>{type.toString()} {count}</p>
<h2>from: {from}</h2>
5 changes: 5 additions & 0 deletions packages/kit/test/apps/basics/test/playwright/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@
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', () => {
Expand Down Expand Up @@ -1530,7 +1535,7 @@
await expect(page.locator('[data-testid="stale-input"]')).toHaveValue('');
});

test('captures and restores function snapshots on shallow navigations', async ({ page }) => {

Check warning on line 1538 in packages/kit/test/apps/basics/test/playwright/client.test.js

View workflow job for this annotation

GitHub Actions / e2e (test:server-side-route-resolution:dev, js, 1/2)

flaky test: captures and restores function snapshots on shallow navigations

retries: 2
await page.goto('/snapshot/helper');
const input = page.locator('[data-testid="default"]');

Expand Down
Loading