Svelte

fix: detect and error on non-idempotent each block keys in dev mode

#17732

Closing issue

Pull request

Merged
R
Rich-Harris
Feb 17, 2026, 6:54 PM

Summary

Fixes

In dev mode, detect when a keyed each block has a key function that returns different values when called multiple times for the same item (non-idempotent). This catches the common mistake of using array literals like [thing.group, thing.id] as keys, which creates a new array object each time and will never match by reference.

  • Adds new each_key_volatile error with helpful message explaining the issue
  • Checks key idempotency in the each block loop during dev mode
  • Provides a clear error instead of the cryptic "Cannot read properties of undefined" that occurred previously
👍 2

Info

Merged at Feb 17, 2026, 9:38 PM
Merged by Rich-Harris
Assignees None
Reviewers None
Labels None
Milestone None

Pro tip: You can prefix GitHub URLs of issues, PRs or discussions with svcl.dev/ to view them on this page! Also try it on a GitHub release ;)