Svelte: Component doesn't get removed in #each with no props/children

Created on 17 Jun 2019  Â·  5Comments  Â·  Source: sveltejs/svelte

Repro: https://svelte.dev/repl/8d5bc96db7634fe0b898b6755b0e7b90?version=3.5.1

Hit the add button, works. Hit the remove button, it fails!

If you add any property to MyComp or give it children, then the remove button begins to work.

bug

Most helpful comment

The original issue is a bug — without a specified key, it should behave as though you'd done this:

{#each arr as item, i (i)}
    <MyComp />
{/each}

The keyed case is fixed in 3.5.3.

All 5 comments

You must use unique keys on list items so that Svelte knows which item to delete. Please, read this part of documentation for a better understanding: Svelte:each

Fix your code, show in 15 line: REPL

@UnwrittenFun, not sure about the completeness of my previous comment. But this may be the solution

This case is broken in 3.5.2 even with unique keys (REPL). Try to click on the remove button.

The original issue is a bug — without a specified key, it should behave as though you'd done this:

{#each arr as item, i (i)}
    <MyComp />
{/each}

The keyed case is fixed in 3.5.3.

No idea how this bug survived in the wild so long. Fixed in 3.6.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rich-Harris picture Rich-Harris  Â·  3Comments

bestguy picture bestguy  Â·  3Comments

davidcallanan picture davidcallanan  Â·  3Comments

thoughtspile picture thoughtspile  Â·  3Comments

ricardobeat picture ricardobeat  Â·  3Comments