Repository navigation
fix(data-table): add headers to table state to prevent brief mismatch with rows (#22714) - #23114
benjamin-t-santos wants to merge 21 commits into
Conversation
fix: move headers to table state to prevent desync with rows a fix for issue 22714. Previously, the header props were passed directly to the table. This led to a situation where the table rendered with the new headers, but old rows (useEffect had not ran yet). Now, both headers and rows are derived from the Data Table state
✅ Deploy Preview for v12-carbon-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v12-carbon-web-components ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
All contributors have signed the DCO. |
fix: revert white space changes formatter deleted whitespace want to keep my diff clean
✅ 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. |
✅ Deploy Preview for v11-carbon-web-components ready!Built without sensitive environment variables
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. |
|
I have read the CLA Document and I hereby sign the CLA. |
|
I have read the DCO document and I hereby sign the DCO. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #23114 +/- ##
==========================================
- Coverage 90.74% 90.71% -0.03%
==========================================
Files 817 817
Lines 79823 79821 -2
Branches 10479 10448 -31
==========================================
- Hits 72432 72409 -23
- Misses 7192 7207 +15
- Partials 199 205 +6
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:
|
fix: do a deep comparison of the state vs incoming headers comparing by keys is not enough header can have same keys but slug, decorator, or label may have changed
fix: use copy of headers for data table state to avoid desync between cellsById and header keys when filtering
fix: create new headers elements for states, better test coverage
|
Hi, would it be possible to get this reviewed again? This is an issue that affects an IBM product. I found it when moving from an older Carbon version to the latest. It did not happen on ~1.78.0, so it is a regression. New headers rendering with the older rows is visible: Screen.Recording.2026-09-03.at.2.45.55.PM.movIf my current changes are not good, please suggest another approach or a workaround (I have tried many but can't find anything that can prevent the desync) |
adamalston
left a comment
There was a problem hiding this comment.
Could you merge main into your branch? It's currently 240 commits behind.
chore: verify DataTable render props use same header/row versions
Co-authored-by: Adam Alston <aalston9@gmail.com>
Closes #22714
Previously,
DataTablepassedheadersdirectly from its props into the render-prop callback, whilerowswere derived from internal state. That state is only updated inside auseEffectwhich runs after the render. If you provided new headers and rows to aDataTablecomponent, on the first render theheaderswere from the new table, while the rows still displayed the previous values.Now,
headersis stored in the component state, and the render-prop callback is called with the stateful values of bothheadersandrows. This ensures they always represent the same table, preventing the visible "flicker".I am open to other approaches/suggestions. Would love to see this fixed; it impacts an IBM product I work on.
Changelog
Changed
DataTable.tsxheaders: DataTableHeader[]is now a member of theDataTableStateinterfacerenderPropsis initialized withstate.headershasHeadersChangedcompares props to stategetDerivedStateFromProps.jsheadersfield to satisfy theDataTableStateinterfacegetDerivedStateFromProps-test.jsheadersfieldTesting / Reviewing
https://stackblitz.com/edit/github-6cyyzrpd?file=src%2FApp.jsx This is a StackBlitz example that demonstrates the bug. I adapted it for a new component using Storybook. I set a breakpoint at the start of the
useEffect()inDataTable.tsxthat determines if the rows or headers change. At that breakpoint, they should not be "desynced". AfteruseEffectruns and the component re-renders, they should both be updated.PR Checklist
As the author of this PR, before marking ready for review, confirm you:
required v12 migration documentation
for any code change that affects v12, or struck through this item because
the PR does not affect v12
More details can be found in the pull request guide