Skip to content

Conversation

@XiaoMing-xmg666
Copy link
Collaborator

@XiaoMing-xmg666 XiaoMing-xmg666 commented Dec 2, 2025

fixes: #6846
Kapture 2025-12-02 at 11 14 00

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @XiaoMing-xmg666, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过在React节点文档中添加一个常见问题解答(FAQ)部分来改进��户体验。该FAQ解决了在使用自定义React节点时scroll-canvas行为可能无法正常工作的问题,并提供了一个清晰的解决方案和代码示例,确保用户能够正确实现画布滚动功能。

Highlights

  • 新增React节点文档FAQ: 为React节点文档添加了一个新的FAQ部分,解决了当光标位于自定义React节点上时scroll-canvas行为无法触发的问题。
  • 解决方案示例: 提供了具体的代码示例,演示如何通过在React自定义节点上添加onWheel事件并将其转发到画布DOM元素来解决滚动问题。
  • 更新示例代码: 更新了react-node.jsx示例文件,以集成上述解决方案并展示scroll-canvas行为。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

这个 PR 很好地为 React 节点和 scroll-canvas 行为的组合添加了 FAQ 文档,解决了社区中一个常见的问题。代码示例清晰地展示了如何通过事件转发来解决滚动问题。

我发现了一些可以改进的地方:

  1. Node 组件的 useEffect 中,添加的 wheel 事件监听器没有在组件卸载时被移除,这可能导致内存泄漏。建议添加一个清理函数。
  2. onWheel 事件处理器中,获取 canvas DOM 元素的方式 graph.context.graph.getCanvas() 是不正确的,因为 graph prop 实际上是 ReactNode 的实例,而不是 G6 的 Graph 实例,这会导致运行时错误。我建议了一种替代方法来正确获取 canvas 元素。

这些修改将使示例代码更加健壮和正确。

Comment on lines +28 to +30
const canvas = graph.context.graph.getCanvas().getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

获取画布 DOM 元素的方式不正确。graph prop 是一个 ReactNode 图形实例,因此 graph.context.graphundefined,这将导致运行时错误。你可以通过 ReactNode 实例的 ownerDocument 属性来获取画布 DOM 元素。

        const canvas = graph.ownerDocument.defaultView.getContextService().getDomElement();
        const evt = new WheelEvent('wheel', e.nativeEvent);
        canvas.dispatchEvent(evt);
Comment on lines +15 to +21
useEffect(() => {
if (ref.current) {
ref.current.parentNode.addEventListener('wheel', (e) => {
e.preventDefault();
});
}
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

useEffect hook 中添加的事件监听器在组件卸载时没有被移除,这可能会导致内存泄漏。应该从 useEffect 返回一个清理函数来移除事件监听器。

  useEffect(() => {
    const parent = ref.current?.parentNode;
    const onWheel = (e) => {
      e.preventDefault();
    };

    if (parent) {
      parent.addEventListener('wheel', onWheel);
    }

    return () => {
      if (parent) {
        parent.removeEventListener('wheel', onWheel);
      }
    };
  }, []);
Comment on lines +266 to +270
useEffect(() => {
if (ref.current) {
ref.current.parentNode.addEventListener('wheel', (e) => e.preventDefault());
}
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

useEffect 中添加的事件监听器在组件卸载时没有被移除,这可能导致内存泄漏。应该从 useEffect 返回一个清理函数来移除事件监听器。作为文档示例,展示最佳实践非常重要。

Suggested change
useEffect(() => {
if (ref.current) {
ref.current.parentNode.addEventListener('wheel', (e) => e.preventDefault());
}
}, []);
useEffect(() => {
const parent = ref.current?.parentNode;
const onWheel = (e) => e.preventDefault();
if (parent) {
parent.addEventListener('wheel', onWheel);
}
return () => {
if (parent) {
parent.removeEventListener('wheel', onWheel);
}
};
}, []);
Comment on lines +277 to +279
const canvas = graph.context.graph.getCanvas().getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

获取画布 DOM 元素的方式不正确。graph prop 是一个 ReactNode 图形实例,graph.context.graph 的值是 undefined,这将导致运行时错误。你可以通过 ReactNode 实例的 ownerDocument 属性来获取画布 DOM 元素。

Suggested change
const canvas = graph.context.graph.getCanvas().getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
const canvas = graph.ownerDocument.defaultView.getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
Comment on lines +266 to +270
useEffect(() => {
if (ref.current) {
ref.current.parentNode.addEventListener('wheel', (e) => e.preventDefault());
}
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

useEffect 中添加的事件监听器在组件卸载时没有被移除,这可能导致内存泄漏。应该从 useEffect 返回一个清理函数来移除事件监听器。作为文档示例,展示最佳实践非常重要。

Suggested change
useEffect(() => {
if (ref.current) {
ref.current.parentNode.addEventListener('wheel', (e) => e.preventDefault());
}
}, []);
useEffect(() => {
const parent = ref.current?.parentNode;
const onWheel = (e) => e.preventDefault();
if (parent) {
parent.addEventListener('wheel', onWheel);
}
return () => {
if (parent) {
parent.removeEventListener('wheel', onWheel);
}
};
}, []);
Comment on lines +277 to +279
const canvas = graph.context.graph.getCanvas().getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

获取画布 DOM 元素的方式不正确。graph prop 是一个 ReactNode 图形实例,graph.context.graph 的值是 undefined,这将导致运行时错误。你可以通过 ReactNode 实例的 ownerDocument 属性来获取画布 DOM 元素。

Suggested change
const canvas = graph.context.graph.getCanvas().getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
const canvas = graph.ownerDocument.defaultView.getContextService().getDomElement();
const evt = new WheelEvent('wheel', e.nativeEvent);
canvas.dispatchEvent(evt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants