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/olive-buses-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: rerun load functions when the number of values of a tracked search parameter changes
8 changes: 4 additions & 4 deletions packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,12 +1167,12 @@ function diff_search_params(old_url, new_url) {
const changed = new Set([...old_url.searchParams.keys(), ...new_url.searchParams.keys()]);

for (const key of changed) {
const old_values = old_url.searchParams.getAll(key);
const new_values = new_url.searchParams.getAll(key);
const old_values = old_url.searchParams.getAll(key).sort();
const new_values = new_url.searchParams.getAll(key).sort();

if (
old_values.every((value) => new_values.includes(value)) &&
new_values.every((value) => old_values.includes(value))
old_values.length === new_values.length &&
old_values.every((value, i) => value === new_values[i])
) {
changed.delete(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

<a data-id="tracked" href="?a={data.count + 1}">Change tracked parameter</a>
<a data-id="untracked" href="?a={data.count}&b={data.count + 1}">Change untracked parameter</a>
<a data-id="duplicate" href="?a={data.count}&a={data.count}">Duplicate tracked parameter</a>
10 changes: 10 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@
expect(await page.textContent('span')).toBe('count: 1');
});

test('load function re-runs when the number of values of a tracked searchParam changes', async ({
page,
clicknav
}) => {
await page.goto('/load/invalidation/search-params/universal?a=0');
expect(await page.textContent('span')).toBe('count: 0');
await clicknav('[data-id="duplicate"]');
expect(await page.textContent('span')).toBe('count: 1');
});

test('server-only load functions are re-run following forced invalidation', async ({
page,
request,
Expand Down Expand Up @@ -660,7 +670,7 @@
expect(await page.textContent('p.shared')).toBe(next_shared);
});

test('+page(.server).js is re-run when server dep is invalidated following goto', async ({

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

View workflow job for this annotation

GitHub Actions / test-kit (22, ubuntu-latest, chromium, current)

flaky test: +page(.server).js is re-run when server dep is invalidated following goto

retries: 2
page
}) => {
await page.goto('/load/invalidation/depends-goto');
Expand Down Expand Up @@ -781,7 +791,7 @@
expect(await page.textContent('h1')).toBe('route.id: /load/invalidation/route/shared/b');
});

test('route.id does not rerun layout if unchanged', async ({ page, clicknav }) => {

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

View workflow job for this annotation

GitHub Actions / test-kit (22, ubuntu-latest, chromium, current)

flaky test: route.id does not rerun layout if unchanged

retries: 2
await page.goto('/load/invalidation/route/shared/unchanged-x');
expect(await page.textContent('h1')).toBe('route.id: /load/invalidation/route/shared/[x]');
const id = await page.textContent('h2');
Expand Down
Loading