Skip to content

bind: in a loop breaks the reference #14625

Open
@macmillen

Description

@macmillen

Describe the bug

I posted this issue already on sveltekit-superforms but it seems to be a Svelte 5 issue. ciscoheat/sveltekit-superforms#509

Apparently in Svelte 5 there is a reactivity problem when you use bind: with a list item in a loop it breaks reference.

  • What I'm wondering about is that while the $form store is updating correctly and reactively the form param inside the onUpdate callback is not up to date

  • This issue seems to only occur in Svelte 5, that's why it seems to me like a bug

<form use:enhance method="post">
	{#each $form.priceRules ?? [] as priceRule}
		<!-- this doesn't work (only when updating another form field afterwards: -->
		<PriceSelection bind:selectedItem={priceRule.priceCategory} />

		<!-- this works: -->
		<!-- <PriceSelection bind:selectedItem={$form.priceRules[0].priceCategory} /> -->
	{/each}

	<button type="submit">submit</button>
</form>

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-svjrzfhz?file=src%2Froutes%2F%2Bpage.svelte

Logs

No response

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: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    svelte: ^5.0.0 => 5.9.0

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions