Skip to content

MudDataGrid: Group server data before rendering it - #14050

Merged
danielchalmers merged 1 commit into
MudBlazor:devfrom
sjaakmarelis:fix/datagrid-group-before-render
Oct 18, 2026
Merged

danielchalmers merged 1 commit into
MudBlazor:devfrom
sjaakmarelis:fix/datagrid-group-before-render

Conversation

@sjaakmarelis

@sjaakmarelis sjaakmarelis commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

After a server load, InvokeServerLoadFunc called StateHasChanged() before GroupItems(). Without a pager that works, because CurrentPageItems goes through FilteredItems, whose getter calls GroupItems(noStateChange: true). With a PagerContent, CurrentPageItems returns GetItemsOfPage(...), which for server data is _serverData.Items directly, 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, and GroupItems() 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 MudTooltip in those cells is disposed before its first OnAfterRender and 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 with ServerData behind a TaskCompletionSource gate and a MudDataGridPager counts 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 whitespace and dotnet format --verify-no-changes on 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:

  • I've read the contribution guidelines
  • My code follows the style of this project
  • I've added or updated relevant unit tests

🤖 Generated with Claude Code

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>

@mudbot mudbot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 TaskCompletionSource gate created with RunContinuationsAsynchronously.
  • 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.

@mudbot mudbot Bot added bug Unexpected behavior or functionality not working as intended needs: visuals Missing screenshots or video for UI bugs or design changes labels Oct 17, 2026
@mudbot

mudbot Bot commented Oct 17, 2026

Copy link
Copy Markdown

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!

@sjaakmarelis

sjaakmarelis commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

After:
https://github.com/user-attachments/assets/9589e80e-de0e-4ab9-b0ed-ccf5949412ee

Here they are

@danielchalmers danielchalmers removed the needs: visuals Missing screenshots or video for UI bugs or design changes label Oct 18, 2026
@danielchalmers

Copy link
Copy Markdown
Member

Thank you!

@danielchalmers
danielchalmers merged commit abc85ad into MudBlazor:dev Oct 18, 2026
13 checks passed
This was referenced Oct 30, 2026
This was referenced Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants