Repository navigation
fix: [DataGrid] unregister the IKeyCodeService listener on dispose - #5517
Draft
Christian Pradelli (christian-sig) wants to merge 1 commit into
Draft
Christian Pradelli (christian-sig) wants to merge 1 commit into
Christian Pradelli (christian-sig) wants to merge 1 commit into
Conversation
FluentDataGrid registers OnKeyDownAsync in OnInitialized but never unregisters it. The scoped service kept every disposed grid alive for the whole circuit, and FluentKeyCodeProvider kept invoking it: on '-' or '+' the stale grid called its released JS module and the console showed 'There was an exception invoking OnKeyDownRaisedAsync'. Fixes microsoft#5516
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused cleanup matches the existing registration contract and includes a direct regression test; tests were not executed during this review.
No open issues 🎉
What changed in this PR
Fixes #5516 by unregistering the DataGrid’s keyboard listener during disposal, preventing disposed grids from remaining referenced and receiving global key events.
Changes:
- Removes the listener in public
DisposeAsync(), independently of JavaScript module initialization. - Adds a regression test that verifies disposal removes the registered listener.
| File | Description |
|---|---|
| tests/Core/Components/DataGrid/FluentDataGridTests.razor | Adds listener-removal regression coverage. |
| src/Core/Components/DataGrid/FluentDataGrid.razor.cs | Unregisters the grid’s keyboard handler during disposal. |
Review effort: Balanced
Vincent Baaij (vnbaaij)
approved these changes
Oct 23, 2026
Collaborator
|
Any reason why this is a draft PR still? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
📖 Description
FluentDataGridregistersOnKeyDownAsyncwithIKeyCodeServiceinOnInitialized, but never unregisters it. Since the service is scoped, every grid disposed during the circuit stays referenced and keeps receiving the global key events fromFluentKeyCodeProvider.On
-or+, the stale grid callsSetColumnWidthDiscreteAsync, which invokes its JS module afterFluentComponentBase.DisposeAsyncreleased it. The console then showsThere was an exception invoking 'OnKeyDownRaisedAsync'.This is a bug fix and not a breaking change: one line in
DisposeAsync().UnregisterListener(Func<FluentKeyCodeEventArgs, Task>)matches onHandlerKeyDown == handler. Delegates of the same method on the same instance compare equal, so it removes only this grid's listener.🎫 Issues
Fixes #5516
👩💻 Reviewer Notes
DisposeAsync()(the one that already disposes_currentPageItemsChanged,_selfReferenceand_scope), not inDisposeAsync(IJSObjectReference). That keeps it independent of whether the JS module was ever imported, for example a grid disposed before its first render.-,+, Shift+R, Shift+S) are global to the document and apply to every live grid regardless of focus.📑 Test Plan
FluentDataGrid_UnregistersKeyCodeListener_OnDisposeinFluentDataGridTests.razor: render a grid, assert one listener;DisposeComponentsAsync(); assert no listeners.devwithout the fix (Assert.Empty() Failure: Collection was not empty) and passes with it.FluentDataGridTests: 171/171 passing locally (net10.0, Linux).Components.Testssuite was not run locally; relying on CI for the rest.✅ Checklist
General
AI contribution declaration
AI assistance is allowed; fully AI-generated or autonomous pull requests without meaningful human review are not accepted. See the AI contribution policy.
Component-specific
⏭ Next Steps
None.
🤖 Generated with Claude Code