Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM order is not guaranteed when using keys #1306

Closed
andyjessop opened this issue Apr 3, 2018 · 2 comments · Fixed by #1309
Closed

DOM order is not guaranteed when using keys #1306

andyjessop opened this issue Apr 3, 2018 · 2 comments · Fixed by #1309

Comments

@andyjessop
Copy link

andyjessop commented Apr 3, 2018

If you add a key to an each block, when that updates, the DOM order of the component is no longer guaranteed - maybe it's moving those updates to the end.

{{#each ones as one @text}}
  <div>{{one.text}}</div>
{{/each}}

{{#each twos as two @text}}
  <div>{{two.text}}</div>
{{/each}}

<script>
  export default {
    data()
      return {
	ones: [{ text: '1' }],
      	twos: [{ text: '2' }],
       };
    },
    oncreate() {
      this.set({ ones: [{ text: '11' }] });
    }
  }
</script>

If you run this, you'll see that the "ones" are placed after the "twos" once the component is created.

REPL: https://svelte.technology/repl?version=1.60.0&gist=e4d16c0723f25a51525fac0b8afd02d8

Rich-Harris added a commit that referenced this issue Apr 4, 2018
ensure correct order of DOM insertions with neighbouring keyed each blocks
@Rich-Harris
Copy link
Member

Fixed in 1.60.2 — thanks

@andyjessop
Copy link
Author

Works nicely, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants