antvis / G6

♾ A Graph Visualization Framework in JavaScript.
https://g6.antv.antgroup.com/
MIT License
11.03k stars 1.3k forks source link

React GNodes are not re-rendered when node data changes #6087

Open jakobert opened 1 month ago

jakobert commented 1 month ago

Describe the bug / 问题描述

If you use a React GNode renderer in a React project, the nodes are not re-rendered when the node data changes.

If node data is displayed in a GNode, it only renders once. After the data was updated, the node still shows the old data even though it was updated in the graph instance.

import { ExtensionCategory, Graph, register } from "@antv/g6";
import { GNode } from "@antv/g6-extension-react";
import CustomNodeRenderer from "./CustomNodeRenderer";

register(ExtensionCategory.NODE, "g", GNode);

const graph = new Graph({
      data,
      layout: {
        type: "circular",
      },
      node: {
        type: "g",
        style: {
          component: CustomNodeRenderer,
        },
      },
      behaviors: ["drag-canvas", "zoom-canvas", "drag-element"],
    });

// ...

// This does not trigger a re-render of the individual GNodes
graph.setData(updatedData);
graph.render();

The longer example for React can be found here: https://gist.github.com/jakobert/80b3f15c68f143a3a4343aacdcb62842

Reproduction link / 重现链接

https://gist.github.com/jakobert/80b3f15c68f143a3a4343aacdcb62842

Steps to Reproduce the Bug or Issue / 重现步骤

No response

G6 Version / G6 版本

🆕 5.x

Operating System / 操作系统

Windows

Browser / 浏览器

Chrome

Additional context / 补充说明

No response

Aarebecca commented 1 month ago

We will confirm the problem soon

gitfrosh commented 1 month ago

I'm experiencing the same behavior!