Skip to content

fix(Chart): can't destroy when dispose#998

Merged
ArgoZhang merged 2 commits into
masterfrom
fix-chart
May 23, 2026
Merged

fix(Chart): can't destroy when dispose#998
ArgoZhang merged 2 commits into
masterfrom
fix-chart

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 23, 2026

Link issues

fixes #997

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Bug Fixes:

  • Ensure chart dispose uses stored instance data to remove resize handlers before destroying charts.

Copilot AI review requested due to automatic review settings May 23, 2026 04:18
@bb-auto bb-auto Bot added the bug Something isn't working label May 23, 2026
@bb-auto bb-auto Bot added this to the v9.2.0 milestone May 23, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts chart disposal logic to correctly access the stored chart instance and its resize handler before destroying it, preventing errors when disposing charts.

Sequence diagram for updated chart dispose logic

sequenceDiagram
    participant Caller
    participant ChartInterop as dispose
    participant Data
    participant BBChart as BootstrapBlazor.Chart
    participant EventHandler
    participant Chart as chart

    Caller->>ChartInterop: dispose(id)
    ChartInterop->>Data: Data.get(id)
    Data-->>ChartInterop: d
    ChartInterop->>Data: Data.remove(id)
    ChartInterop->>BBChart: removeOptionsById(id)
    alt [d exists]
        ChartInterop->>EventHandler: off(window, resizeHandler)
        ChartInterop->>Chart: destroy()
    end
Loading

File-Level Changes

Change Details Files
Fix chart dispose logic to correctly handle stored chart metadata and detach the resize handler before destruction.
  • Retrieve stored chart entry into a local variable before removing it from the Data registry.
  • Destructure the chart instance and its resizeHandler from the stored entry instead of assuming Data.get returns a bare chart object.
  • Unsubscribe the window resize event using the extracted resizeHandler to avoid leaks or errors.
  • Call chart.destroy() on the extracted chart instance only when a stored entry exists.
src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js

Assessment against linked issues

Issue Objective Addressed Explanation
#997 Ensure that disposing a Chart correctly destroys the underlying chart instance and unregisters the resize event handler.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang ArgoZhang merged commit d051e91 into master May 23, 2026
2 of 3 checks passed
@ArgoZhang ArgoZhang deleted the fix-chart branch May 23, 2026 04:19
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider renaming the temporary variable d in dispose to something more descriptive (e.g., chartData or entry) to make the intent of the code clearer.
  • The destructuring const { chart, chart: { resizeHandler } } = d; is a bit hard to read; consider either adding a brief comment about the shape of the stored data or restructuring it for clarity (e.g., first extract chart then get chart.resizeHandler).
  • It may be safer to guard against a missing resizeHandler before calling EventHandler.off(window, 'resize', resizeHandler) to avoid potential runtime errors if older or malformed entries lack that property.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider renaming the temporary variable `d` in `dispose` to something more descriptive (e.g., `chartData` or `entry`) to make the intent of the code clearer.
- The destructuring `const { chart, chart: { resizeHandler } } = d;` is a bit hard to read; consider either adding a brief comment about the shape of the stored data or restructuring it for clarity (e.g., first extract `chart` then get `chart.resizeHandler`).
- It may be safer to guard against a missing `resizeHandler` before calling `EventHandler.off(window, 'resize', resizeHandler)` to avoid potential runtime errors if older or malformed entries lack that property.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang review requested due to automatic review settings May 23, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Chart): can't destroy when dispose

1 participant