图在快速 addShape/removeShape 的时候出现报错: Uncaught TypeError: Cannot read property 'length' of undefined #5285
HuColin posted onGitHub
G6 Version
4.x
Describe the bug
@antv/G6 4.8.24 同出现这个问题,在自定义节点的 setState 中,在对 group 进行 addShape 的时候
我的操作是(通过 addShape 给自定义节点添加边框)快速 hover 自定义节点来快速重复执行 setState,期间有大量 shape 的创建/销毁行为
之后浏览器爆出Uncaught TypeError: Cannot read property 'length' of undefined
的异常,通过定位发现如下位置抛出异常
<img width="833" alt="image" src="https://github.com/antvis/G6/assets/16102181/485b5077-03f2-40a8-bf6f-858d09f1db29">
这里 cfg.children
为 undefined,但是仍然调用自身递归,在下一步 for 循环的时候, undefined.length
报错
定位到应该是 g-canvas 库中 clearChanged
函数在 for 循环的时候没有对 children 判断是否为空
<img width="738" alt="image" src="https://github.com/antvis/G6/assets/16102181/929bf3f2-a3a8-459a-894a-ef532199da79">
报错是定位在压缩后的代码 → https://g.alicdn.com/code/lib/antv-g6/4.8.24/g6.min.js:1:127018
在源码中,在递归调用 clearChanged 的时候,是有判断元素是否被销毁,但是构建后的代码里面似乎没有......,这个不确定是什么原因导致的
Your Example Website or App
无
Steps to Reproduce the Bug or Issue
无
Expected behavior
在递归调用时需要判断空值
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 120
Additional context
No response