sveltejs / sveltejs/kit

Inconsistent page.params reactivity in top level async derived

Open
#14,996 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

When page.params param is used in a top level await derived it sometimes gets updated (without a reactivity change) after the top-level await executes but the value should always be known and updated before running the top level await/component.

Reproduction

Svelte: 5.45.2

SvelteLab

Click on any route link in main route, it should always return 1 length but it very often returns 0 then go back and re-entry it, click it enough times and it returns 0.

As a workaround you can store the value in some global state before navigating with goto instead of using <a> link.

https://github.com/user-attachments/assets/0b4ae3fc-a048-419e-a8da-f175c75940b6

Logs

System Info
System:
    OS: Linux 6.14 Fedora Linux Asahi Remix 42 (Forty Two [Adams])
    CPU: (8) arm64 unknown
    Memory: 7.42 GB / 31.11 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.19.0 - /home/jk/.n/bin/node
    Yarn: 1.22.22 - /home/jk/.n/bin/yarn
    npm: 10.9.3 - /home/jk/.n/bin/npm
    bun: 1.3.3 - /home/jk/.bun/bin/bun
  Browsers:
    Chromium: 142.0.7444.175
    Firefox: 145.0.1
    Firefox Developer Edition: 145.0.1
Severity

serious, but I can work around it

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior using the linked SvelteLab example and inspect the mentioned route files under src/routes/bug/[x]/ and src/routes/bug/. Start with +page.svelte and the related +page.server.js, +layout.svelte, and +layout.js files to trace page.params through the top-level await. Done means clicking the main route link consistently produces the expected length of 1 without the global-state workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.