Skip to content

A bug when vdom trying to update children when data being changed in some case #7199

Closed
@maple-leaf

Description

@maple-leaf

Version

2.5.9

Reproduction link

https://codepen.io/maple-leaf/pen/BmgaqG

Steps to reproduce

  1. open the codepen demo
  2. open devtool if u are on chrome
  3. click change data which will raise error button
  4. now you should see an error like this: TypeError: Cannot read property 'key' of undefined.
  5. refresh demo page
  6. click safe to change data here button
  7. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions