-
Notifications
You must be signed in to change notification settings - Fork 777
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
Duplicate keys is not reported in a clear way #409
Comments
Duplicate keys as in duplicate keys in an object? |
Issue is not reported in a clear way ;-) |
The problematic case is where you have two different vnodes with the same key. This causes the diffing algorithm to do the wrong thing (dropping nodes that shouldn't be dropped), silently. |
There's still a bit of ambiguity here. Can you show an example? |
Sure. I have some examples I can put here in the morning. Just to be clear, though, the issue comes up specifically when you reuse the same key in multiple vnodes that have the same parent. By the key, I simply mean the argument called "key" in the constructor, here: https://github.com/Matt-Esch/virtual-dom/blob/master/vnode/vnode.js#L12 |
Here's a concrete example. vdom1: https://gist.github.com/yminsky/e01531a14bc96e9b0bb474cc07a43aa6 The patch is the patch between vdom1 and vdom2, but setting the DOM to vdom1 and then applying the patch yields a different state than setting it to vdom2 directly. I got these patches by dumping the JSON from the browser. |
Instead, it just leads to incorrect patches being created, which causes things to blow up farther down the line at some unspecified point in time.
It would be nice if duplicating keys would lead to an exception that explicitly flagged this problem.
Even better would be for the diffing to be done in a correct, if less efficient way, in that case.
The text was updated successfully, but these errors were encountered: