Skip to content

Propagate ScrollToItemAsync cancellation to pending item-provider work - #68478

Merged
ilonatommy merged 1 commit into
mainfrom
fix-virtualize-refresh-cancellation
Aug 14, 2026
Merged

ilonatommy merged 1 commit into
mainfrom
fix-virtualize-refresh-cancellation

Conversation

@ilonatommy

Copy link
Copy Markdown
Member

Fixes #68475.

Propagates ScrollToItemAsync cancellation to the underlying ItemsProvider request. This prevents canceled scrolls from waiting for or applying stale provider results. QuickGrid's debounce now also observes request cancellation. Adds regression unit test.

@ilonatommy ilonatommy added this to the 11.0-rc1 milestone Aug 13, 2026
@ilonatommy ilonatommy self-assigned this Aug 13, 2026
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components feature-blazor-virtualization This issue is related to the Blazor Virtualize component labels Aug 13, 2026
@dariatiurina

Copy link
Copy Markdown
Contributor

We should also add token here, no?

@ilonatommy ilonatommy changed the title Improve cancellation story around virtualize component Propagate ScrollToItemAsync cancellation to pending item-provider work Aug 13, 2026
@ilonatommy

Copy link
Copy Markdown
Member Author

We should also add token here, no?

That would be much broader change and would require public API

+public Task RefreshDataAsync(CancellationToken cancellationToken)

I updated the title to scope it down.

@dariatiurina

Copy link
Copy Markdown
Contributor

We should also add token here, no?

That would be much broader change and would require public API

+public Task RefreshDataAsync(CancellationToken cancellationToken)

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?

@ilonatommy
ilonatommy marked this pull request as ready for review August 13, 2026 14:58
@ilonatommy
ilonatommy requested a review from a team as a code owner August 13, 2026 14:58
Copilot AI lite review requested due to automatic review settings August 13, 2026 14:58
@ilonatommy

Copy link
Copy Markdown
Member Author

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.

Copilot AI 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.

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 ScrollToItemAsync cancellation into Virtualize.RefreshDataCoreAsync via an explicit overload and a linked refresh CancellationTokenSource, with safe CTS cleanup and _loading reset on cancellation.
  • Updates QuickGrid’s provider debounce (and test-asset providers) to observe ItemsProviderRequest.CancellationToken during 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 throw OperationCanceledException when the token is canceled, so the subsequent IsCancellationRequested check and return 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 return default.
        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.

@ilonatommy
ilonatommy merged commit 401bbfb into main Aug 14, 2026
44 of 46 checks passed
@ilonatommy
ilonatommy deleted the fix-virtualize-refresh-cancellation branch August 14, 2026 13:14

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 938fd4fd Deployed Aug 13, 2026 by ilonatommy via conclusion #889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components feature-blazor-virtualization This issue is related to the Blazor Virtualize component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Propagate ScrollToItemAsync cancellation to pending item-provider work

3 participants