Repository navigation
fix: compare normalized DataTable rows - #23154
Conversation
✅ Deploy Preview for v12-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v12-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #23154 +/- ##
==========================================
- Coverage 89.67% 89.65% -0.02%
==========================================
Files 639 639
Lines 58865 58870 +5
Branches 8334 8270 -64
==========================================
- Hits 52785 52782 -3
- Misses 5914 5922 +8
Partials 166 166
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
[AI agent review — Carbon grounded] · Suggested Improvements Reviewed by: bob · Commit: 4890503 Recommendation2 findings worth considering: 2 minor. This PR is on the right track. The findings below are suggestions worth considering before or shortly after merging — none are hard blockers, but addressing them would improve correctness or maintainability. Findings (2)Category — how each finding was established:
SummaryThis PR adds a cell-value comparison when detecting DataTable row changes, normalizing the incoming rows before comparing to avoid false positives from new object references. 2 minor findings: both relate to asymmetries between how nextRows and currentRows are constructed that can defeat the optimization in common edge cases. DetailsAdditional FindingsThe following findings could not be mapped to specific lines in the diff: 1. nextRows spread includes extra row properties absent from currentRows causing false positive hasRowsChangedFile: nextRows is built via { ...row, disabled: ..., isExpanded: ..., isSelected: ... }, which spreads all properties on the incoming row object — including any user-defined custom properties beyond the header keys and the three standard boolean fields. currentRows, by contrast, is built by a headers.reduce seeded with only {id, disabled, isExpanded, isSelected}, and only picks up per-header cell values — it will never contain a custom property like metadata or customFlag that a caller adds to their RowType. When such extra properties are present, isEqual(nextRows[i], currentRows[i]) returns false on every render, hasRowsChanged is always true, and getDerivedStateFromProps is called on every parent re-render — defeating the entire optimization. Build nextRows with the same shape as currentRows: seed it with the three normalized booleans plus id, then reduce over headers to add per-column values rather than spreading the raw row object. 2. Normalization asymmetry for optional boolean fields between nextRows and currentRowsFile: nextRows applies ?? false to disabled, isExpanded, and isSelected, converting undefined to false. currentRows reads these same fields directly from state.rowsById[id] without any normalization. If getDerivedStateFromProps stores undefined for a row that never had those props set (rather than normalizing to false), then for every such row isEqual receives {disabled: false} vs {disabled: undefined}, which are not equal — making hasRowsChanged always true. Apply the same ?? false normalization when reading from state in currentRows (e.g. disabled: row.disabled ?? false) so both objects are normalized identically before comparison. Review artifacts:
Estimated Token Usage:
Note: Token estimates are approximate and based on character count (1 token ≈ 4 characters). An AI agent generated this review. Human review is advised before acting on any findings. |
4388837
|
The content of this pull request will be made available as part of our next release. For the full schedule of upcoming releases, check out our Release Radar page. |
No issue. #23114 (comment)
Compared normalized
DataTablerow values before rebuilding state.Changelog
Changed
DataTablerow values before rebuilding state.Testing / Reviewing
yarn test packages/react/src/components/DataTablePR Checklist
As the author of this PR, before marking ready for review, confirm you:
Updated documentation and storybook examplesFollowed therequired v12 migration documentation
for any code change that affects v12, or struck through this item because
the PR does not affect v12
Addressed any impact on accessibility (a11y)Tested for cross-browser consistencyMore details can be found in the pull request guide