sveltejs / sveltejs/kit

Inconsistent state during navigation: `data` (route params) updates before awaited remote query in `$derived`

Open
#15,860 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

When a page uses both data from a route param and an awaited remote query derived from that same param, navigating between instances of the route briefly exposes an inconsistent state: data.symbol already reflects the new
route, while the awaited query result still holds the value from the previous navigation. This produces transient UI glitches and, in keyed {#each} blocks, triggers each_key_duplicate.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-gzoodfhc?embed=1&file=src%2Froutes%2Fsym-%5Bsymbol%5D%2F%2Bpage.svelte

Steps:

  1. Click the AAPL link.
  2. Click the MSFT link.
  3. Open the console.
Logs
Logging `allSymbols` during the transition:


['MSFT', 'AAPL', 'GOOGL', 'AMZN']   // initial
['AAPL', 'AAPL', 'GOOGL', 'AMZN']   // intermediate — new data.symbol + stale peers
['AAPL', 'MSFT', 'GOOGL', 'AMZN']   // final


And the runtime warning:


Uncaught Svelte error: each_key_duplicate
Keyed each block has duplicate key `AAPL` at indexes 0 and 1
System Info
REPL
Severity

annoyance

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

Start with the linked StackBlitz reproduction, especially src/routes/sym-[symbol]/+page.svelte, and reproduce the AAPL-to-MSFT navigation while watching the console. Trace how the route parameter, data, and awaited remote query in $derived update during navigation. Done means the intermediate inconsistent state and each_key_duplicate warning no longer occur.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.