antvis/G6

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

jakobert posted onGitHub

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

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


We will confirm the problem soon

posted by Aarebecca 9 months ago

I'm experiencing the same behavior!

posted by gitfrosh 9 months ago

In the latest version, this issue has been resolved.

posted by Aarebecca 6 months ago

Fund this Issue

$0.00
Funded

Pull requests