Skip to content

Avoid sending JSInterop calls when component is disposed - #69517

Merged
ilonatommy merged 4 commits into
dotnet:mainfrom
ilonatommy:fix-69501
Sep 25, 2026
Merged

ilonatommy merged 4 commits into
dotnet:mainfrom
ilonatommy:fix-69501

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Virtualize<TItem> can be disposed while an asynchronous JS interop operation is pending. When the operation completes, the lifecycle continuation may issue another interop call using the component's disposed DotNetObjectReference, resulting in an ObjectDisposedException and circuit termination.

This change centralizes disposal handling in VirtualizeJsInterop, which owns the object reference. It consists of:

  • Marking the interop wrapper as disposed before starting cleanup. That prevents JS interop calls after disposal started.
  • Handling ObjectDisposedException when disposal races with an invocation already starting.

Fixes #69501

The reported issue was reproduced on Aspire dashboard on the ~400th navigation attempt before the fix and was proven to be gone after this fix - checked with 1k navigations.

@ilonatommy ilonatommy self-assigned this Sep 25, 2026
@ilonatommy
ilonatommy requested a review from a team as a code owner September 25, 2026 12:57
@ilonatommy ilonatommy added the area-blazor Includes: Blazor, Razor Components label Sep 25, 2026
Copilot AI lite review requested due to automatic review settings September 25, 2026 12:57
@ilonatommy ilonatommy added the feature-blazor-virtualization This issue is related to the Blazor Virtualize component label Sep 25, 2026

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.

Copilot review overview

🟢 Approval recommended

Only minor test-coverage nits remain, with no approval-blocking issues.

Review effort: Lite
Findings: None

What changed in this PR

Prevents Virtualize<TItem> from issuing JS interop calls after disposal begins, including disposal races.

Changes:

  • Adds disposal guards and race-safe exception handling.
  • Adds regression tests for pending interop operations.
File Changes
src/​Components/​Web/​test/​Virtualization/​VirtualizeTest.cs Adds disposal-race regression tests.
src/​Components/​Web/​src/​Virtualization/​VirtualizeJsInterop.cs Centralizes disposal state and guarded JS calls.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@ilonatommy

Copy link
Copy Markdown
Member Author

/ba-g Failures look like #62308. No Virtualize failures among the failed tests.

@ilonatommy
ilonatommy disabled auto-merge September 25, 2026 15:18
@ilonatommy
ilonatommy merged commit 890971a into dotnet:main Sep 25, 2026
29 of 31 checks passed
@ilonatommy

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

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.

Blazor Virtualize can use a disposed DotNetObjectReference during rapid navigation

3 participants