G
G copied to clipboard
react严格模式下webglRender初始化时会报错
- OS: macOS 15.6.1 (24G90)
- Browser chrome
- Version @antv/[email protected] 、@antv/[email protected]
Steps To Reproduce
- 初始化一个画布
- 创建一个圆
- 把圆添加进画布
import { Canvas, CanvasEvent, Circle } from "@antv/g";
import { Renderer } from "@antv/g-webgl";
import { useEffect, useRef } from "react";
export function Test() {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!ref.current) return;
const renderer = new Renderer();
const canvas = new Canvas({
container: ref.current,
width: 600,
height: 500,
renderer,
});
const circle = new Circle({
style: {
r: 50,
fill: "#1890FF",
stroke: "#F04864",
lineWidth: 4,
cursor: "pointer",
},
});
const fn = () => {
canvas.appendChild(circle);
};
canvas.addEventListener(CanvasEvent.READY, fn);
return () => {
canvas.removeEventListener(CanvasEvent.READY, fn);
canvas.destroy();
};
}, []);
return <div ref={ref}></div>;
}
如果关闭react的严格模式不会报错,打开会报错,
报错信息如下:
Error handled by React Router default ErrorBoundary: TypeError: Cannot read properties of undefined (reading 'destroy')
at RenderGraphPlugin.ts:277:19
at SyncHook.ts:15:16
at Array.forEach (
Based on the provided bug report, here's the analysis:
Title: react严格模式下webglRender初始化时会报错
Body:
- OS: macOS 15.6.1 (24G90)
- Browser: chrome
- Version: @antv/[email protected], @antv/[email protected]
Steps To Reproduce:
- Initialize a canvas.
- Create a circle.
- Add the circle to the canvas.
import { Canvas, CanvasEvent, Circle } from "@antv/g";
import { Renderer } from "@antv/g-webgl";
import { useEffect, useRef } from "react";
export function Test() {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!ref.current) return;
const renderer = new Renderer();
const