Repository navigation
Propagate ScrollToItemAsync cancellation to pending item-provider work - #68478
Conversation
|
We should also add token here, no? |
ScrollToItemAsync cancellation to pending item-provider work
That would be much broader change and would require public API I updated the title to scope it down. |
Then maybe we would want to move this to 12 and then just deprecate non-token version? |
It can be API proposal that could collect feedback from the community. I don't any current mentions with scenarios that would require that overload. |
There was a problem hiding this comment.
Pull request overview
This PR improves Blazor virtualization cancellation behavior by ensuring Virtualize.ScrollToItemAsync cancellation flows into the underlying ItemsProviderRequest, preventing stale or canceled refresh work from completing and applying results. It also updates QuickGrid and test providers to respect request cancellation, and adds a regression test to validate the behavior.
Changes:
- Propagates
ScrollToItemAsynccancellation intoVirtualize.RefreshDataCoreAsyncvia an explicit overload and a linked refreshCancellationTokenSource, with safe CTS cleanup and_loadingreset on cancellation. - Updates QuickGrid’s provider debounce (and test-asset providers) to observe
ItemsProviderRequest.CancellationTokenduring delayed work. - Adds a unit test that blocks an items provider, cancels
ScrollToItemAsync, and asserts both the scroll task and provider request are canceled.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/Web/test/Virtualization/VirtualizeTest.cs | Adds regression coverage ensuring scroll cancellation cancels the provider request. |
| src/Components/Web/src/Virtualization/Virtualize.cs | Threads scroll cancellation into refresh/provider requests and safely manages refresh CTS lifecycle/state. |
| src/Components/test/testassets/BasicTestApp/VirtualizationAnchorMode.razor | Makes the test provider delay cancellable via the request token. |
| src/Components/test/testassets/BasicTestApp/QuickGridTest/QuickGridScrollComponent.razor | Makes the test provider delay cancellable via the request token. |
| src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs | Updates provider debounce to observe request cancellation during the delay. |
Suppressed comments (1)
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs:567
Task.Delay(100, request.CancellationToken)will throwOperationCanceledExceptionwhen the token is canceled, so the subsequentIsCancellationRequestedcheck andreturn default;are never reached. If the intent is to treat cancellation as a clean early-return (and avoid relying on upstream exception suppression), catch the cancellation around the delay and returndefault.
await Task.Delay(100, request.CancellationToken);
if (request.CancellationToken.IsCancellationRequested)
{
return default;
}
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Fixes #68475.
Propagates
ScrollToItemAsynccancellation to the underlyingItemsProviderrequest. This prevents canceled scrolls from waiting for or applying stale provider results. QuickGrid's debounce now also observes request cancellation. Adds regression unit test.