Skip to content

Commit aa7f700

Browse files
authored
[fix] route invalidation comparison based on url and route, not on id (#8399)
Fixes #8398
1 parent ac082cf commit aa7f700

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

.changeset/sweet-hairs-roll.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 route id comparison for load change detection

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ export function create_client({ target, base }) {
709709
let server_data = null;
710710

711711
const url_changed = current.url ? id !== current.url.pathname + current.url.search : false;
712-
const route_changed = current.route ? id !== current.route.id : false;
712+
const route_changed = current.route ? route.id !== current.route.id : false;
713713

714714
const invalid_server_nodes = loaders.reduce((acc, loader, i) => {
715715
const previous = current.branch[i];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/** @type {import('./$types').LayoutLoad} */
22
export function load({ route }) {
3-
return { route };
3+
return { route, random: Math.random() };
44
}

packages/kit/test/apps/basics/src/routes/load/invalidation/route/shared/+layout.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
</script>
55

66
<h1>route.id: {data.route.id}</h1>
7+
<h2>random id: {data.random}</h2>
78
<slot />
89

910
<a href="/load/invalidation/route/shared/a">/load/invalidation/route/shared/a</a>
1011
<a href="/load/invalidation/route/shared/b">/load/invalidation/route/shared/b</a>
12+
13+
<a href="/load/invalidation/route/shared/unchanged-x">/load/invalidation/route/shared/unchanged-x</a>
14+
<a href="/load/invalidation/route/shared/unchanged-y">/load/invalidation/route/shared/unchanged-y</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>[x]</p>

packages/kit/test/apps/basics/test/client.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,16 @@ test.describe('Invalidation', () => {
10691069
expect(await page.textContent('h1')).toBe('route.id: /load/invalidation/route/shared/b');
10701070
});
10711071

1072+
test('route.id does not rerun layout if unchanged', async ({ page, clicknav }) => {
1073+
await page.goto('/load/invalidation/route/shared/unchanged-x');
1074+
expect(await page.textContent('h1')).toBe('route.id: /load/invalidation/route/shared/[x]');
1075+
const id = await page.textContent('h2');
1076+
1077+
await clicknav('[href="/load/invalidation/route/shared/unchanged-y"]');
1078+
expect(await page.textContent('h1')).toBe('route.id: /load/invalidation/route/shared/[x]');
1079+
expect(await page.textContent('h2')).toBe(id);
1080+
});
1081+
10721082
test('$page.url can safely be mutated', async ({ page }) => {
10731083
await page.goto('/load/mutated-url?q=initial');
10741084
await expect(page.getByText('initial')).toBeVisible();

0 commit comments

Comments
 (0)