Skip to content

fix: compare normalized DataTable rows - #23154

Merged
heloiselui merged 1 commit into
carbon-design-system:mainfrom
adamalston:n/a-rows
Sep 21, 2026
Merged

heloiselui merged 1 commit into
carbon-design-system:mainfrom
adamalston:n/a-rows

Conversation

@adamalston

@adamalston adamalston commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

No issue. #23114 (comment)

Compared normalized DataTable row values before rebuilding state.

Changelog

Changed

  • Compared normalized DataTable row values before rebuilding state.

Testing / Reviewing

yarn test packages/react/src/components/DataTable

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Followed the
    required v12 migration documentation
    for any code change that affects v12, or struck through this item because
    the PR does not affect v12
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

@adamalston
adamalston requested a review from a team as a code owner August 27, 2026 21:38
@netlify

netlify Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v12-carbon-react ready!

Name Link
🔨 Latest commit 4890503
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-react/deploys/6a90ae453859c900081901f1
😎 Deploy Preview https://deploy-preview-23154--v12-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for v12-carbon-web-components ready!

Name Link
🔨 Latest commit 4890503
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-web-components/deploys/6a90ae451b9da90008d727f8
😎 Deploy Preview https://deploy-preview-23154--v12-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

✅ Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4890503
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6a90ae45184e2f00087c1e6f
😎 Deploy Preview https://deploy-preview-23154--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

✅ Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 4890503
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6a90ae450023ff0008f8a2ca
😎 Deploy Preview https://deploy-preview-23154--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

✅ Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 4890503
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6a90ae453859c900081901ed
😎 Deploy Preview https://deploy-preview-23154--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (7bd6bbb) to head (4890503).
⚠️ Report is 111 commits behind head on main.

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              
Flag Coverage Δ
main-packages 87.15% <100.00%> (+<0.01%) ⬆️
web-components 90.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@carbon-monitor-agent

Copy link
Copy Markdown
Collaborator

[AI agent review — Carbon grounded] · Suggested Improvements

Reviewed by: bob · Commit: 4890503
Carbon verification: Carbon-specific claims verified using Carbon Builder skill (primary authority) and Carbon MCP (fallback).

Recommendation

2 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:

  • Cat 1 — a Carbon-specific claim (does this component accept this prop, attribute or variant?), verified against the Carbon Builder skill or Carbon MCP.
  • Cat 2 — generic correctness, accessibility or duplication, established from the diff alone.
Area Category Severity Finding File
General Cat 2 minor nextRows spread includes extra row properties absent from currentRows causing false positive hasRowsChanged packages/react/src/components/DataTable/DataTable.tsx
General Cat 2 minor Normalization asymmetry for optional boolean fields between nextRows and currentRows packages/react/src/components/DataTable/DataTable.tsx

Summary

This 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.

Details

Additional Findings

The 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 hasRowsChanged

File: packages/react/src/components/DataTable/DataTable.tsx (Line 89)
Severity: minor — Consider addressing — not a hard blocker.

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 currentRows

File: packages/react/src/components/DataTable/DataTable.tsx (Line 91)
Severity: minor — Consider addressing — not a hard blocker.

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:

  • Input tokens: ~13,476
  • Output tokens: ~39,641
  • Total tokens: ~53,117

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.

@heloiselui
heloiselui requested review from devadula-nandan and removed request for amal-k-joy September 9, 2026 12:20
@heloiselui
heloiselui added this pull request to the merge queue Sep 21, 2026
Merged via the queue into carbon-design-system:main with commit 4388837 Sep 21, 2026
63 of 64 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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.

@adamalston
adamalston deleted the n/a-rows branch September 21, 2026 14:37
sangeethababu9223 pushed a commit to sangeethababu9223/carbon that referenced this pull request Sep 22, 2026

This branch was successfully deployed

1 active deployment
@carbon/react storybook preview — 48905038 Deployed Aug 27, 2026 by adamalston via react-storybook-preview #41862
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants