Skip to content

Conversation

hakenr
Copy link
Member

@hakenr hakenr commented May 6, 2025

@jirikanda Please review. If you're good with the change, I'll go ahead and update a few other components that currently dispose the CTS (HxAutosuggest, HxSearchBox, HxInputTags, etc.).

Also, we could try setting _paginationRefreshDataCancellationTokenSource to null once the data load operation finishes (both QuickGrid and FluentUI-DataGrid do this so the GC can collect the CTS ASAP), though it probably won't make much of a difference.

Reference implementations:

@hakenr hakenr requested review from Copilot and jirikanda May 6, 2025 11:28
Copy link
Contributor

@Copilot 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 removes the disposal of the cancellation token source (CTS) in HxGrid to mitigate potential ObjectDisposedException issues when tasks are still running, while adding tests to verify the cancellation behavior remains correct.

  • Removed CTS disposal in HxGrid.razor.cs and set it to null instead
  • Added tests in HxGrid_Cancellation_Tests.cs to validate cancellation behavior after component disposal

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
HxGrid.razor.cs Removed disposal of the CTS with an explanatory comment to prevent ObjectDisposedException issues that can occur when tasks still reference the CTS
HxGrid_Cancellation_Tests.cs Introduced tests to ensure cancellation is requested properly and that no ObjectDisposedException is thrown after component disposal

@jirikanda
Copy link
Contributor

I guess NOT OK, see line 730 in HxGrid.razor.cs

@hakenr hakenr requested a review from Copilot May 13, 2025 13:03
Copy link
Contributor

@Copilot 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 removes the disposal of the CancellationTokenSource in the HxGrid component to avoid potential ObjectDisposedExceptions and adds tests to verify proper cancellation behavior when the component is disposed.

  • Removed CTS disposal in RefreshPaginationOrLoadMoreDataCoreAsync and Dispose method
  • Added tests to ensure cancellation behavior works as intended

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
HxGrid.razor.cs Removed CTS disposal to prevent ObjectDisposedExceptions and reinitialized it on refresh/dispose
HxGrid_Cancellation_Tests.cs Added tests to validate cancellation behavior when the grid is disposed

@hakenr hakenr merged commit 052a5e4 into master May 13, 2025
1 check passed
@hakenr hakenr deleted the hxgrid-cts-dispose branch May 13, 2025 14:33
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.

2 participants