Description
Version
2.5.9
Reproduction link
https://codepen.io/maple-leaf/pen/BmgaqG
Steps to reproduce
- open the codepen demo
- open devtool if u are on chrome
- click
change data which will raise error
button - now you should see an error like this:
TypeError: Cannot read property 'key' of undefined
. - refresh demo page
- click
safe to change data here
button - now you should not see an error like before, and data being updated correctly
What is expected?
maybe same behavior like both should raise an error, but if raise error, maybe duplicate key
error should be showed too which will help developer easier to find what data is killing page.
What is actually happening?
both data have duplicate keys, but behavior is different
why error being raise when you click change data which will raise error
button?
Because the data will raise error has some special changes. It remove all keys except duplicate key 'b' compared to initial data and the order is different.
This will make updateChildren
function in vdom/patch.js
hit this code section, which will create a oldKeyToIdx
. And then when first key 'b' comes, it will set value of b
in oldKeyToIdx
to undefined
, and then next key b
comes, it will compare old node and new node via function sameNode. But this time, index of old node which key is b
is undefined now. So a js error is being raised.