Repository navigation
MudDataGrid: Group server data before rendering it - #14050
Conversation
After a server load, InvokeServerLoadFunc called StateHasChanged() before GroupItems(). Without a pager that works, because CurrentPageItems goes through FilteredItems, which groups on the fly. With a PagerContent, CurrentPageItems returns the server items directly while the group definition is still the one computed before the load (none on the first load), so the rows rendered ungrouped and the next render rebuilt every row component under its group. Every component in the first set was disposed right after its first render. Group first, then render. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The fix calls GroupItems() before StateHasChanged() in InvokeServerLoadFunc. Before, a grid with server data and a pager rendered its rows ungrouped first, then built every row again under its group. Moving the call fixes that, and the number of renders after a load stays the same.
When the grid isn't groupable, GroupItems() doesn't render on its own before the first render. The StateHasChanged() call that now follows it covers that case, so the old guarantee of a render after every load still holds. When the grid is grouped, the extra StateHasChanged() does no harm because the renderer queues only one render.
The new test and viewer components follow AGENTS.md:
- The load is held behind a
TaskCompletionSourcegate created withRunContinuationsAsynchronously. - The test uses no sleeps or blocking waits.
- File names are under 40 characters.
- The helper component has
[ViewerHidden]. - The test has an XML summary and a name without the forbidden suffixes.
There were no earlier findings, and I found nothing to fix before merging.
|
Could you post a short before and after video of the change from your own local run? Please upload the video file directly to this pull request, for example by dragging it into a comment, so it plays here. I'm an AI assistant — If I missed something or made a mistake, please let me know in a reply! |
|
Thank you! |
After a server load,
InvokeServerLoadFunccalledStateHasChanged()beforeGroupItems(). Without a pager that works, becauseCurrentPageItemsgoes throughFilteredItems, whose getter callsGroupItems(noStateChange: true). With aPagerContent,CurrentPageItemsreturnsGetItemsOfPage(...), which for server data is_serverData.Itemsdirectly, while the group definition is still the one from before the load (none on the first load, when there were no items). So the rows rendered ungrouped, andGroupItems()then rendered them again under their groups: every row component was built twice, and every component of the first set was disposed right after its first render.That second effect is what made it costly for us: in Interactive Server, a
MudTooltipin those cells is disposed before its firstOnAfterRenderand is never removed from the popover provider (#14049). A grouped grid with a pager left one orphaned popover per tooltip on every load.Change
Group first, then render.
GroupItems()keeps refreshing the drop containers and requesting its own render, so the number of renders after a load stays the same; only the first one is now already grouped.Related: #13964 keeps the server order when there is no pager. It touches
FilteredItems, not this path.Test
DataGridGroupedServerDataWithPagerBuildsCellsOnce: a grouped grid withServerDatabehind aTaskCompletionSourcegate and aMudDataGridPagercounts the cell components it creates. 3 rows give 6 cells without the change and 3 with it.Before/After:
Nothing rendered changes after the load settles. Measured with Playwright against a local build of this branch, Interactive Server, a grouped grid with 30 rows, a tooltip per row and an empty
PagerContent: on every open, 30 rows were removed and rebuilt and 30 popovers stayed orphaned before; 0 and 0 after.Verification:
dotnet test --project src/MudBlazor.UnitTests/MudBlazor.UnitTests.csproj -p:SkipBunCompile=true(6220 passed, 2 skipped, together with the popover change),dotnet format whitespaceanddotnet format --verify-no-changeson the changed files.AI assistance: the analysis (runtime probes in our app, decompiling 9.9/9.11), the change, the test and this description were prepared with Claude Code (Anthropic), following AGENTS.md, and reviewed by me.
Checklist:
🤖 Generated with Claude Code