Skip to content

react严格模式下webglRender初始化时会报错 #2076

Open

Description

@zhe-he
  • OS: macOS 15.6.1 (24G90)
  • Browser chrome
  • Version @antv/g@6.1.28 、@antv/g-webgl@2.0.52

Steps To Reproduce

  1. 初始化一个画布
  2. 创建一个圆
  3. 把圆添加进画布
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 ()
at SyncHook2.call (SyncHook.ts:13:20)
at RenderingService2.destroy (RenderingService.ts:332:24)
at Canvas2.destroy (Canvas.ts:387:32)
at cleanExistedCanvas (canvas.ts:18:52)
at new Canvas2 (Canvas.ts:198:7)
at index.tsx?t=1761104888817:12:24
at Object.react_stack_bottom_frame (react-dom-client.development.js:25989:20)

Activity

  1. github-actions commented on Oct 22, 2025

    @github-actions
    Contributor

    Based on the provided bug report, here's the analysis:

    Title: react严格模式下webglRender初始化时会报错

    Body:

    • OS: macOS 15.6.1 (24G90)
    • Browser: chrome
    • Version: @antv/g@6.1.28, @antv/g-webgl@2.0.52

    Steps To Reproduce:

    1. Initialize a canvas.
    2. Create a circle.
    3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions