Skip to content

fix: select examples new graph load twice - #5024

Merged
GaoFuhong merged 1 commit into
antvis:masterfrom
peng-shuo:refactor-examples
Feb 2, 2026
Merged

GaoFuhong merged 1 commit into
antvis:masterfrom
peng-shuo:refactor-examples

Conversation

@peng-shuo

Copy link
Copy Markdown
Contributor

修复选择组件的例子中,画布加载两次的问题

📝 Description

将选择组件的例子中,

  1. 逻辑部分的加载方式从类组件更改为函数式组件
  2. 加上正确的生命周期开始注册,结束注销的方式
  3. 解决由于重复加载后,出现的grid画面重复的问题(出现原因是两次重新加载期间没有正确的注销画布)

🖼️ Screenshot

0a36d5ac-6f0d-4a68-833f-09b8cbc82467 0d3ea272-a64e-4634-b012-35de25017649 0eede995-b5b5-4d1a-afb3-6b0c50fabdbf 8fd92a76-5d61-43bd-b18c-3c4628de9776 f85fc31b-5256-432b-9b9e-f2d642ce2038
Before After
❌ ✅

💡 Motivation and Context

🧩 Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Enhancement (changes that improvement of current feature or performance)
  • Refactoring (changes that neither fixes a bug nor adds a feature)
  • Test Case (changes that add missing tests or correct existing tests)
  • Code style optimization (changes that do not affect the meaning of the code)
  • Docs (changes that only update documentation)
  • Chore (changes that don't modify src or test files)

🔍 Self Check before Merge

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @peng-shuo, 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!

此拉取请求旨在解决选择组件示例中画布重复加载的错误。通过将组件转换为函数式组件,并利用 useEffect 钩子实现画布的正确初始化和销毁,从而避免了画布实例的重复创建和网格重复显示的问题,提升了示例的稳定性和用户体验。

Highlights

  • 组件重构: 将 SelectionExample 组件从类组件重构为函数式组件,以利用 React Hooks。
  • 画布生命周期管理: 使用 useEffect 和 useRef 实现了画布实例的正确生命周期管理,确保在组件卸载时正确销毁画布。
  • 解决重复加载问题: 修复了选择组件示例中画布重复加载导致网格重复显示的问题,通过在每次加载前正确注销旧画布来解决。
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. ↩

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

本次 PR 将 SelectionExample 组件从类组件重构为了函数式组件,并使用 useEffect Hook 来管理 Graph 实例的生命周期。这个改动是正确的,通过在 useEffect 的清理函数中调用 graph.dispose(),有效地解决了之前因组件重复加载而导致的画布渲染两次的问题。代码实现清晰,遵循了现代 React 的最佳实践。我只发现了一个可以移除未使用变量的小改进点,具体请看我的评论。

@hustcc

hustcc commented Jan 31, 2026 •

Copy link
Copy Markdown
Member

@peng-shuo 感谢!估计其他的 examples 也还是 class component 的写法,有兴趣都改掉吗?应该可以使用 ai 都解决。

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@GaoFuhong
GaoFuhong merged commit 9973e20 into antvis:master Feb 2, 2026
8 checks passed
@peng-shuo

Copy link
Copy Markdown
Contributor Author

@hustcc ok

@peng-shuo 感谢!估计其他的 examples 也还是 class component 的写法,有兴趣都改掉吗?应该可以使用 ai 都解决。

Ok,最新的提交已经将这个问题修复了

lxfu1 pushed a commit that referenced this pull request Oct 15, 2026
Co-authored-by: 彭硕 <justshuo@foxmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants