sveltejs / kit

web development, streamlined

Home Page:https://kit.svelte.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different behaviour if you check two or more times the `type` in `afterNavigate`?

frederikhors opened this issue · comments

Describe the bug

This is crazy, I know.

But if I use this code:

afterNavigate(({ type, to }) => {
    if (type !== 'enter' && type !== 'popstate') return;

    const paramPagination = to.url.searchParams.get(paramPaginationKey);
});

paramPagination is null.

If I use this code instead:

afterNavigate(({ type, to }) => {
    if (type === 'goto') return;

    const paramPagination = to.url.searchParams.get(paramPaginationKey);
});

then paramPagination is not null and is correct (an object like { page: 1, size: 2 }).

I know this is crazy but I can reproduce this 100 times with same steps. I lost one entire hour on this!

Why is that?

Reproduction

I'm building one...

System Info

npmPackages:
    @sveltejs/adapter-static: 3.0.2 => 3.0.2
    @sveltejs/kit: 2.5.18 => 2.5.18
    @sveltejs/vite-plugin-svelte: 3.1.1 => 3.1.1
    svelte: 5.0.0-next.183 => 5.0.0-next.183

Severity

blocking all usage of SvelteKit