Skip to content

Navigating between pages of a layout can re-evaluate $derived with wrong values before navigating #15431

@phi-bre

Description

@phi-bre

Describe the bug

As promised in sveltejs/svelte#17787 (comment) I managed to create a reproduction of the issue.

Basically, navigating between +page.svelte of a +layout.svelte can re-evaluate their $derived using the wrong params.id before actually navigating to the other +page.svelte.

In contrast to my initial assumptions, it actually requires the layout to await a long running promise AND rerun based on params changes.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-qhdxrvzq?file=src%2Froutes%2F%2Blayout.svelte

Logs

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.0 => 7.0.1 
    @sveltejs/kit: ^2.53.2 => 2.53.2 
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.4 
    svelte: ^5.53.5 => 5.53.5 
    vite: ^7.2.2 => 7.3.1

Severity

serious, but I can work around it

Additional Information

I don't think #14996 (comment) applies here, as I don't see how synchronously accessing params.id before an async boundary is actually entered would be an edge case of the reactivity system.

Also, forkPreloads: false does not fix this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions