Matt-Esch/virtual-dom

diff replace/remove rather than remove

bloodyKnuckles opened this issue · 1 comments

Given:

[a,b] and [b]

The resulting diff patch replaces a with b then removes b, rather than simply removing a.

Here's an example:
http://requirebin.com/?gist=a1fe075b4553c3b44354657c1d6625d5

vdom1 = h('div', [
  h('div', 'div stuff'),
  h('script', {src: 'bundle.js'})
])

vdom2 = h('div', [
  h('script', {src: 'bundle.js'})
])

diff(vdom1, vdom2)

Results in:

1 VNODE DIV -> SCRIPT
3 REMOVE SCRIPT

The problem in this particular case is that bundle.js gets downloaded again and therefore re-executed, resetting state vars, etc.

A) Don't use vdom to include scripts, this is a bad idea and will keep causing re-download problems and you're going to have a bad time.
B) key solves exactly this

Fixed your example to show it: http://requirebin.com/?gist=chrisinajar/0d5e8d8346ac420ea76c1eab8b673db5