Skip to content

SvelteKit goto doesn't re-render state when navigating to a page in the same directory #11116

Open
@Beyondo

Description

@Beyondo

Describe the bug

Sveltekit does not react to goto navigations properly in a special case.

Reproduction

When I goto('/users/user-[UID_SLUG]'), it does not change the state reactively. But when I go from '/users/user-[UID_SLUG]' to /, it changes the state reactively.

The two workarounds I have are either using an anchor link with data-sveltekit-reload (non-reactive) or setting the state manually when the user clicks the anchor link which is kinda frustrating.

But what I've noticed in the 2nd workaround, is that I don't just set $currentUser = {...};, no, I actually have to do this:

$currentUser = null;
setTimeout(() => {
    $currentUser = { ... };
}, 0);

Something weird is going on and I honestly cannot figure it out.

Logs

No response

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 6.01 GB / 31.86 GB
  Binaries:
    Node: 19.5.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.3.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (119.0.2151.58)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @sveltejs/adapter-cloudflare: ^2.3.3 => 2.3.3
    @sveltejs/adapter-node: ^1.3.1 => 1.3.1
    @sveltejs/adapter-static: ^2.0.2 => 2.0.2
    @sveltejs/kit: ^1.20.4 => 1.22.3
    svelte: ^4.0.5 => 4.1.1
    vite: ^4.4.2 => 4.4.7

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions