Skip to content

textfield values incorrectly retained #77

Closed
@seriousManual

Description

@seriousManual

svelte-cli version 1.0.4

template:

{{#each samples as sample}}
    {{sample}}: <input type="text"><br>
{{/each}}

bootstrap:

<!doctype html>
<html>
<head>
    <title>My first Svelte app</title>
</head>
<body>
<main></main>
<script src='helloWorld.js'></script>
<script>
    var app = new helloWorld({
        target: document.querySelector( 'main' ),
        data: {
            samples: ['foo', 'bar', 'bax', 'baz']
        }
    });

    setTimeout(() => {
        app.set({samples: ['foo', 'baz']});
    }, 6000)
</script>
</body>
</html>

Reproduce:

  1. Load Page
  2. Enter values from 1 to 4 in the text boxes
  3. wait for timeout to fire

Expected:
image

Actual:
image

Looks like the relation between the loop pass and the actual dom element is not kept, so the 3rd and 4th input box are removed though the 2nd and 3rd should have been removed.

Update:
The same thing happens in React when no key is provided to the root element of each loop pass.
In React though it is enforced that there is only one root element in each iteration whereas in svelte this is not necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions