bcakmakoglu / vue-flow

A highly customizable Flowchart component for Vue 3. Features seamless zoom & pan 🔎, additional components like a Minimap 🗺 and utilities to interact with state and graph.
https://vueflow.dev/
MIT License
3.74k stars 242 forks source link

🐛 [BUG]: TypeError: Cannot read properties of undefined (reading 'id') #1568

Closed mshamaseen closed 1 month ago

mshamaseen commented 1 month ago

Is there an existing issue for this?

Current Behavior

console error, saying 'TypeError: Cannot read properties of undefined (reading 'id')'

it happens when I add custom nodes.

Expected Behavior

No error should be triggered.

Steps To Reproduce

am not sure as it happens occasionally, but look at the code description below you will understand the issue

Relevant log output

at applyChanges (vue-flow-core.mjs:4966:25)
    at Object.applyNodeChanges2 [as applyNodeChanges] (vue-flow-core.mjs:6416:12)
    at nodesChangeHandler (vue-flow-core.mjs:7792:19)
    at vue-flow-core.mjs:5105:52
    at Array.map (<anonymous>)
    at Proxy.trigger (vue-flow-core.mjs:5105:40)
    at updateNodeDimensions (vue-flow-core.mjs:6104:31)
    at vue-flow-core.mjs:9563:24

Anything else?

Looking at the updateNodeDimensions function the changes member is set here only if the doUpdate is true.

the issue happen because it is set using changes[i] = ... instead of changes[] = ...

The issue happen when doUpdate is false, then in the next loop it becomes true, the changes value will be: `[empty, {...}, {...}] Where the index 0 is empty because doUpdate was false at index 0.

then when looping thro this changes, the first element will be undefined or empty. take applyChanges function for example, currentChange).id will throw an error here because currentChange is actually empty.

bcakmakoglu commented 1 month ago

Thanks for reporting, will be fixed in the next patch.

bcakmakoglu commented 1 month ago

Fixed with 1.39.3