sveltejs/svelte

`params` becomes empty object (`{}`) after any async work

Closed this issue · 4 comments

Describe the bug

params becomes {} after any async work

<script>
  const { params } = $props();

  console.log(params); // { slug: 'test-1' }
  await Promise.resolve()
  console.log(params); // {}
</script>

This bug was introduced in 5.42.0. Still present in 5.43.0

Reproduction

Steps to reproduce:

  1. Open the browser console
  2. Hover either link and observe the console

https://stackblitz.com/edit/sveltejs-kit-template-default-b5xxkxnj?file=src%2Froutes%2F%2Bpage.svelte,src%2Froutes%2F[slug]%2Ftest.remote.ts,src%2Froutes%2F[slug]%2F%2Bpage.svelte

Logs

✅ First remote function call:
test-1

❌ Second remote function call, with the same parameter:
Remote function schema validation failed: [
  {
    kind: 'schema',
    type: 'string',
    input: undefined,
    expected: 'string',
    received: 'undefined',
    message: 'Invalid type: Expected string but received undefined',
    requirement: undefined,
    path: undefined,
    issues: undefined,
    lang: undefined,
    abortEarly: undefined,
    abortPipeEarly: undefined
  }
]

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:
    svelte: 5.42.0 => 5.43.0 
    @sveltejs/kit: 2.48.3 => 2.48.3

Severity

blocking an upgrade

@paoloricciuti is this actually a kit issue?

  • I tried downgrading svelte from 5.42.0 to 5.41.4 and it works fine.
  • I tried downgrading @sveltejs/kit from 2.48.3 to 2.42.0 and it was still broken.

Or is it a kit incompatibility with the new forking feature?

Uh actually I was just executing @Ocean-OS directives here 😄 will check tomorrow

Yeah, I noticed the same. Downgrading makes the issue disappear, but in that version Svelte doesn’t seem to prerender the page, it just loads it. The problem happens when hovering: it updates params to the hovered page’s params, then resets them back to the current page’s params. Since both reference the same object, when the async task finishes it sees the updated (now empty) state.

Probably just need to clone the params object in the page context so it’s not shared by reference.