Skip to content

Can't assign result of preloadData to local state after using pushState #14960

@danieldiekmeier

Description

@danieldiekmeier

Describe the bug

In my app, I'm using shallow routing together with preloadData. However, ever since the fork API was added in svelte@5.42.0, preloading does not work anymore.

The data gets loaded (I can see the fetch request, and I can log the result), but when I put the new data into local $state, my component does not rerender. I'm basically only doing this:

let data = $state("");

async function preload() {
  const result = await preloadData(`/other`);
  data = result.data.foo;
}

I added a reproduction that uses almost the same code. If I can do anything else, let me know.

Thank you for all the work on async/fork. I know you already fixed a bunch of bugs in the last few weeks, and I repeatedly read the changelog and thought that my bug would now be fixed, but sadly not yet. I hope the reproduction helps.

Reproduction

https://github.com/danieldiekmeier/sveltekit-repro-preload-data

If you start the reproduction with pnpm run dev, it will hopefully explain itself.

This is what it looks like when you go to /other with shallow routing and click the "Preload" button a few times:

Image

As you can see, the Result: is not updated, and the $inspect call runs twice after ever click.


If you go to /other directly, clicking the button successfully replaces the result, and there's only one $inspect line per click.

Image

Logs

System Info

System:
    OS: macOS 15.6.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.26 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.21.0 - /Users/daniel/.local/share/mise/installs/node/22.21.0/bin/node
    Yarn: 1.22.19 - /Users/daniel/.local/share/mise/installs/node/22.21.0/bin/yarn
    npm: 10.9.4 - /Users/daniel/.local/share/mise/installs/node/22.21.0/bin/npm
    pnpm: 10.23.0 - /Users/daniel/.local/share/mise/installs/node/22.21.0/bin/pnpm
    Deno: 2.5.6 - /Users/daniel/.local/share/mise/installs/deno/2.5.6/bin/deno
  Browsers:
    Chrome: 142.0.7444.176
    Edge: 142.0.3595.90
    Firefox: 144.0.2
    Firefox Developer Edition: 143.0
    Safari: 18.6
    Safari Technology Preview: 18.4
  npmPackages:
    @sveltejs/adapter-auto: ^7.0.0 => 7.0.0
    @sveltejs/kit: ^2.47.1 => 2.49.0
    @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1
    svelte: ^5.41.0 => 5.43.14
    vite: ^7.1.10 => 7.2.4

Severity

blocking an upgrade

Additional Information

I can keep my project on 5.41.4 as a workaround, but of course I'd like to update one day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions