The issue involves reactivity in Svelte's legacy mode, which requires understanding of internal mechanisms.
The issue describes a bug where `{@const}` inside `{#each}` does not update correctly when a prop-derived value is only consumed inside an array callback in Svelte's legacy mode. The problem is clear, but fixing it requires understanding Svelte's reactivity system and the differences between legacy and runes modes. The maintainer has indicated that this works correctly in runes mode, suggesting the issue is specific to legacy mode.
A {@const} inside {#each} does not invalidate when its reactive dependency
arrives via a prop and that dependency is only referenced inside an array
callback (.find(), .filter(), .some(), etc.) rather than in the outer
expression.
From the template's perspective the prop changed, a sibling {@const} that
reads the prop directly updates correctly, but the {@const} whose expression
only touches the prop inside a callback closure stays frozen at its previous
value.
Both must be present:
No transition, no {#if} toggle, no async wrapper needed.
Link to REPL https://svelte.dev/playground/9e909f44f22a406a80a639c6ecd69496?version=latest
The playground shows both the buggy and the fixed pattern side by side, driven
by the same prop. Click any button — selectedItemId updates correctly in both
sections, but only the Fixed section reflects the change in the derived
selectedItem.
Clicking any button updates selectedItemId. Both sections should then resolve
selectedItem and show the correct seat count.
selectedItemId updates in both sections. The Bug section never shows
seats — selectedItem stays undefined on every click. The Fixed section
works correctly.
Make the prop-derived scalar appear in the outer expression before the callback:
<!-- Buggy: selectedItemId hidden inside callback -->
{@const selectedItem = group.items.find((item) => item.id === selectedItemId)}
<!-- Fixed: selectedItemId visible in outer expression -->
{@const selectedItem = selectedItemId && group.items.find((item) => item.id === selectedItemI
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!