Matt-Esch / virtual-dom

A Virtual DOM and diffing algorithm
MIT License
11.67k stars 777 forks source link

Apparent bug in diff/patch logic #407

Closed yminsky closed 8 years ago

yminsky commented 8 years ago

I have a case where the application of a patch fails with the following exception:

Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'.

Here are gists showing the new and old and the patch. There's a reorder instruction in the patch, which looks a little suspicious.

Original vDOM: https://gist.github.com/yminsky/008d5f563381588c343d5d974fd1040a New vDOM: https://gist.github.com/yminsky/7b04b3372fc4f851b09e983ed5a80398 Patch: https://gist.github.com/yminsky/a2eb3cd860bb731a4947e488f0dfb869

@hhugo

yminsky commented 8 years ago

Ugh. Just figured out the real issue. It turns out, I had a duplicated key, which lead to the diff/patch algorithm silently doing the wrong thing. Ideally, duplicate keys would be detected and reported as such.