Describe the bug
Hi,
It seems that using a goto() + invalidate() triggers twice an invalidate method which calls twice the load() method from +page.server. This happens only when using custom identifiers as stated by official documentation : https://kit.svelte.dev/docs/modules#$app-navigation-invalidate
If the argument is given as a string or URL, it must resolve to the same URL that was passed to fetch or depends (including query parameters). To create a custom identifier, use a string beginning with [a-z]+: (e.g. custom:state) — this is a valid URL.
GIVEN load() depending on (foo:bar) WHEN goto + invalidate(foo:bar) THEN load method called twice (KO)
GIVEN load() depending on (foo-bar) WHEN goto + invalidate(foo-bar) THEN load method called once (OK)
If I just misunderstood this documentation, please let me know :)
Maybe invalidate + goto should be used together ? But goto doesn't seem to invalidate at every searchParams change (when modyfing existing searchParam value)
Thanks for your work !
Reproduction
Minimal reproduction:
https://stackblitz.com/edit/stackblitz-starters-axljya?file=src%2Froutes%2F%2Bpage.svelte
+page.js
import { goto, invalidate } from "$app/navigation";
/** @type {import('./$types').PageData} */
export let data;
async function onBtnClickKO () {
await goto(`?page=${data.page +1 ?? 0}`);
await invalidate('search:something');
};
async function onBtnClickOK () {
await goto(`?page=${data.page +1 ?? 0}`);
await invalidate('search-something');
};
</script>
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
<button type="button" on:click={onBtnClickKO}>Invalidate KO</button>
<button type="button" on:click={onBtnClickOK}>Invalidate OK</button>
+page.server.js
const searchParams = new URL(url).searchParams;
const page = +(searchParams.get('page') ?? 0);
depends('search:something');
depends('search-something');
console.log('LOAD, THIS LOG SHOULD BE DISPLAYED ONLY ONCE PER REFRESH');
return {
page,
results: [{ a: '1', b: '2' }]
};
};
Logs
No response
System Info
"@sveltejs/kit": "1.22.1",
Severity
annoyance
Additional Information
No response
Describe the bug
Hi,
It seems that using a goto() + invalidate() triggers twice an invalidate method which calls twice the load() method from +page.server. This happens only when using custom identifiers as stated by official documentation : https://kit.svelte.dev/docs/modules#$app-navigation-invalidate
GIVEN load() depending on (foo:bar) WHEN goto + invalidate(foo:bar) THEN load method called twice (KO)
GIVEN load() depending on (foo-bar) WHEN goto + invalidate(foo-bar) THEN load method called once (OK)
If I just misunderstood this documentation, please let me know :)
Maybe invalidate + goto should be used together ? But goto doesn't seem to invalidate at every searchParams change (when modyfing existing searchParam value)
Thanks for your work !
Reproduction
Minimal reproduction:
https://stackblitz.com/edit/stackblitz-starters-axljya?file=src%2Froutes%2F%2Bpage.svelte
+page.js
+page.server.js
Logs
No response
System Info
Severity
annoyance
Additional Information
No response