Skip to content

MudDataGrid: Use key row item instead of row index.#10845

Merged
ScarletKuro merged 2 commits intoMudBlazor:devfrom
Jaron-jp:fix/datagrid-row-key
Feb 15, 2025
Merged

MudDataGrid: Use key row item instead of row index.#10845
ScarletKuro merged 2 commits intoMudBlazor:devfrom
Jaron-jp:fix/datagrid-row-key

Conversation

@Jaron-jp
Copy link
Contributor

@Jaron-jp Jaron-jp commented Feb 10, 2025

Description

This is reverting a change made for .net 8 version of MudBlazor that causes issues (not sure exactly when it was done).

MudDataGrid was changed such that the <tr> elements were given a @key equal to the row index of the <tr> instead of the user supplied item. This does not match the purpose of @key which is to help maintain the relationship between Blazor components in a sequence and their corresponding models. This can cause odd and subtle issues. See bug report for details.

fixes #10802

How Has This Been Tested?

Visually confirmed using code referenced in Reproduction link of #10802.
Also added bUnit test that verifies child components of rows are recreated - indicating the row's key is using the row item. Verified the test fails with the old MudDataGrid code (which keys off row index) and passes with new code (keys off row item).

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added bug Unexpected behavior or functionality not working as intended PR: needs review labels Feb 10, 2025
@ScarletKuro ScarletKuro changed the title Make MudDataGrid @key rows off row item instead of row index. MudDataGrid: Use key row item instead of row index. Feb 10, 2025
@ScarletKuro
Copy link
Member

I think you could integrate the test from you issue to the bUnit, so it doesn't get broken in future like it was before, this is very easy to break without getting noticed

@sonarqubecloud
Copy link

@Jaron-jp
Copy link
Contributor Author

@ScarletKuro Added a bUnit test case as requested. I verified the test fails with the old code and passes with the new. Unrelated ValidAttributeTests are failing it seems here, but I saw that's an issue with a sdk change you mentioned elsewhere.

@ScarletKuro ScarletKuro merged commit 0a1d1b9 into MudBlazor:dev Feb 15, 2025
3 of 4 checks passed
@Jaron-jp Jaron-jp deleted the fix/datagrid-row-key branch February 18, 2025 14:34
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.

MudDataGrid is misusing @key on its <tr> elements which can cause subtle issues

2 participants