Improve QuickGrid diagnostics for mismatched GridSort types#67413
Improve QuickGrid diagnostics for mismatched GridSort types#67413BharatRamsf3693 wants to merge 7 commits into
Conversation
|
Thanks for your PR, @BharatRamsf3693. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Pull request overview
This PR improves QuickGrid’s diagnostics when a column ends up being constructed with a different TGridItem than its parent QuickGrid<TGridItem> (commonly via a mismatched GridSort<TSortItem>), by cascading the grid’s item Type to columns and validating during column registration. It also adds an E2E page and tests covering several mismatch scenarios.
Changes:
- Cascade the grid item type (
typeof(TGridItem)) fromQuickGridto descendant columns. - Validate column
TGridItemvs. grid item type and throw a clearerInvalidOperationExceptionon mismatch. - Add a dedicated test page and E2E tests to assert the improved error output in interactive server mode.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/QuickGrid/QuickGridTypeMismatch.razor | Adds a test page exercising multiple QuickGrid/column type mismatch scenarios via error boundaries. |
| src/Components/test/E2ETest/Tests/QuickGridInteractiveTest.cs | Adds E2E assertions verifying the improved mismatch diagnostics are surfaced to developers. |
| src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor | Cascades the grid item Type to descendants using a named CascadingValue. |
| src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor.cs | Adds a named cascading parameter to receive the grid’s item Type. |
| src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/Columns/ColumnBase.razor | Implements the type mismatch validation and throws a clearer exception. |
|
All review comments have been addressed, and the implementation has been further optimized. |
There is a "resolve conversation" button you can use under each review comment to mark that. |
ilonatommy
left a comment
There was a problem hiding this comment.
Public API changes from community PRs are not planned anymore for this release. We can take only internal fixes, otherwise it will wait for .net12.
| } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Run git checkout main on this file.
| { | ||
| string displayName = string.IsNullOrWhiteSpace(Title) ? "(unnamed)" : Title; | ||
| throw new InvalidOperationException($"Column '{displayName}' has TGridItem={typeof(TGridItem).FullName} which does not match the parent QuickGrid's item type. Ensure the GridSort type parameter matches the grid's item type."); | ||
| } |
There was a problem hiding this comment.
Why did we move the check from base to TemplateColumn? In QuickGrid we support custom columns. This fix adds better diagnostics only for blazor columns, custom ones will still hit the original issue. E.g. add test for PropertyColumn to see that it will have the same issue.
Improve QuickGrid diagnostics for mismatched GridSort types
Description
This change improves the developer experience when a
GridSort<TSortItem>type does not match theQuickGrid<TGridItem>item type used by aTemplateColumn.Previously, configuring a
TemplateColumnwith aGridSortcreated for a different item type could cause the column to fail initialization with an unclear error, making the root cause difficult to identify. This update adds an explicit validation check duringTemplateColumninitialization and throws a more actionable exception when the column cannot bind to the parent grid due to a type mismatch.Before
After
Changes included
TemplateColumn<TGridItem>during component initialization.QuickGridbecause of an item-type mismatch.InvalidOperationExceptionwith guidance to verify that theGridSorttype parameter matches the grid's item type.(unnamed)when not specified.TGridItemtype.QuickGriditem type does not match.Example exception
Fixes #56437