Skip to content

Order of html tags changes when using key > if #5680

@MarkTanashchuk

Description

@MarkTanashchuk

I need to display html when variable (in this repl - num) is truthy

And I also need to animate first tag after each change of another variable(slide)

If I have html structure like this:

{#key animateOnChangeVariable}
  {#if variableIsTrythy}
    <div class="first">First tag</div>
  {/if}
{/key}
<div class="second">Second tag</div>

And if num is changed, first tag is inserted after second (html order is changed)

REPL
https://svelte.dev/repl/3ba09b8c428c4ee58c77ff477b5fa632?version=3.29.7

If {#if} and {#key} swapped, everything works correctly

Also, if you have several buttons at the same time, which change num by clicking - an error is thrown (uncomment second button, uncomment function and get error div1 is not defined).

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