antvis/G6

npm run test:integration时,src/runtime/graph.ts报错:Cannot read properties of undefined (reading 'ready') #5141

k644606347 posted onGitHub

问题描述

npm run test:integration时,src/runtime/graph.ts报错:Cannot read properties of undefined (reading 'ready') <img width="541" alt="image" src="https://github.com/antvis/G6/assets/6951527/93e23e5d-9ccd-45c5-8740-f99f02c4c651">

原因

以data-process-parallel-edges.spec.ts为例,运行npm run test:integration时,会通过tests/integration/utils/canvas.tscreateContext创建多个canvas,然后new ExtGraph传给src/runtime/graph.ts; <img width="722" alt="image" src="https://github.com/antvis/G6/assets/6951527/e8803dca-e6a6-44d6-8bb8-aac3cf340468">

src/runtime/graph.ts判断传入canvas后,会直接使用外部传入的各种canvas对象: <img width="648" alt="image" src="https://github.com/antvis/G6/assets/6951527/4d7da059-4a0e-47a4-b66d-161caf01acd9">

但是createContext少生成了labelCanvastransientLabelCanvassrc/runtime/graph.ts也少接收了labelCanvas,这导致src/runtime/graph.ts内,调用这两个canvas对象的ready属性时报错undefined <img width="600" alt="image" src="https://github.com/antvis/G6/assets/6951527/dbf089ba-2fee-4e08-894d-da58a38add1a">

解决方案

  1. createContext生成labelCanvastransientLabelCanvas并传入src/runtime/graph.tssrc/runtime/graph.ts内接受这两个参数,但感觉传入的canvas对象已经很多了。。。,而且很多demo都得改下,追加传入这两个canvas给graph,<img width="939" alt="image" src="https://github.com/antvis/G6/assets/6951527/f87a46da-4b02-40d0-b3c6-1caf5d877827">

  2. 在````src/runtime/graph.ts内细化下各种类型canvas```传值的判断,防止某些canvas未传入,类似这样:

    <img width="616" alt="image" src="https://github.com/antvis/G6/assets/6951527/3aa65bab-c12c-4f39-a40a-ca02d1709397">

重现链接

test

重现步骤

运行npm run test:integration,过一会报错中断

预期行为

npm run test:integration不报错

平台

  • 操作系统: [macOS]
  • 网页浏览器: [Google Chrome,]
  • G6 版本: [5.0.0-beta.28]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


相关代码已过时

posted by Aarebecca 11 months ago

Fund this Issue

$0.00
Funded

Pull requests