Skip to content

Dev/fix stream output#297

Merged
XinyueDu merged 3 commits intomainfrom
dev/fix-stream-output
Jan 27, 2026
Merged

Dev/fix stream output#297
XinyueDu merged 3 commits intomainfrom
dev/fix-stream-output

Conversation

@XinyueDu
Copy link
Contributor

@XinyueDu XinyueDu commented Jan 27, 2026

PR includes

Screenshot

image
Before After

Copilot AI review requested due to automatic review settings January 27, 2026 03:49
@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

⚠️ No Changeset found

Latest commit: cfc96f9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gemini-code-assist
Copy link

Summary of Changes

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

This pull request addresses an issue related to chart rendering and interaction, particularly concerning how chart data is parsed and how charts respond to resizing events. The changes aim to make the chart component more resilient to parsing errors and ensure proper resizing behavior across different chart libraries, specifically distinguishing between G6 and other chart types.

Highlights

  • Improved Chart JSON Parsing: The parsing of chart JSON content has been refactored to initialize chartJson as nullable and handle parsing errors more robustly by deferring error handling until after all hooks are called. This ensures a more stable component lifecycle.
  • Enhanced Chart Resizing Logic: The chart resizing logic (handleResize) has been moved and now explicitly checks for G6 chart types (isG6) earlier in the component's lifecycle. This allows for specific resize and autofit methods for G6 charts, and changeSize for other chart types, improving responsiveness and correctness.
  • Consistent Type Handling: A dedicated chartType variable is now used consistently throughout the component after successful parsing of chartJson, replacing previous direct usage of type from chartJson. This improves clarity and type safety, especially with the introduction of null assertion operators (!) where chartJson is guaranteed to be present.
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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

🎊 PR Preview cfc96f9 has been successfully built and deployed to https://antvis-GPT-Vis-preview-pr-297.surge.sh

🕐 Build time: 19.019s

🤖 By surge-preview

Copy link

@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

This pull request refactors the RenderVisChart component to handle JSON parsing before React hooks are called, correctly adhering to the Rules of Hooks, which improves component stability. It also enhances variable naming by renaming type to chartType to avoid shadowing. However, a critical security vulnerability was identified in the JSON parsing and component lookup logic. This could lead to a Denial of Service (DoS) crash if malicious or unexpected content is provided, as the code does not account for JSON.parse returning null and lacks validation that the chart type is an own property of the components object before rendering. Additionally, a separate comment highlights an issue where the debounced resize handler's cancel() method is called on every render.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a React hooks violation error that occurred during streaming output of chart content. The issue (#296) manifested when incomplete JSON was being parsed during streaming, causing conditional early returns before all hooks were called, which violated React's Rules of Hooks.

Changes:

  • Moved JSON parsing and type extraction to occur before any hooks
  • Relocated the isG6 calculation and handleResize useMemo hook before conditional returns
  • Deferred error handling to after all hooks are called, ensuring consistent hook count across renders

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@XinyueDu XinyueDu merged commit a71a319 into main Jan 27, 2026
9 checks passed
@XinyueDu XinyueDu deleted the dev/fix-stream-output branch January 27, 2026 07:28
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.

官网流式输出报错

3 participants