fix: grid column widths resetting when pin state changes - #1552
Conversation
Resizing a column and then pinning or unpinning any column wiped all user column widths (and custom column order) back to defaults. The "reset on column identity change" effect in DataGrid depends on defaultColumnPinning, whose identity also changes whenever the URL-backed pinnedColumnIds prop round-trips after a pin update, so the effect re-ran and cleared columnSizing/columnOrder state. Guard the reset with the column definition identity key so it only fires when the set of columns actually changes (issue #1371). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Summary by CodeRabbit
WalkthroughUpdated DataGrid reset logic so column order, pinning, and sizing reset only when the column identity changes. Added a controlled pinning regression test confirming a resized column remains at 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
|
Compute preview deployed. Branch: |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Fixes #1371
Root cause
Column resizing itself works (TanStack
onChangeresize, 50–400px clamp, per-table state) — but the "reset column order/pinning/sizing when column identities change" effect inDataGrid.tsxlistsdefaultColumnPinningin its deps, and that memo's identity changes whenever thepinnedColumnIdsprop changes, which happens on every pin/unpin (pinning round-trips through URL state). Result, reproduced live: resize a column, pin or unpin any column → all column widths and custom column order silently reset. This alone makes resizing feel broken.Fix
Guard the reset effect with a ref of the last-seen column-identity key so it only fires when the column-id set actually changes.
Verification
Remaining observations from the investigation (not addressed here, noted on the issues): widths still reset on remount so per-table persistence never survives switching tables; the 400px max cap may read as "broken" for wide JSON columns; the resize handle's effective hit area is ~8px and missing it starts a drag-reorder (relates to #1372).
🤖 Generated with Claude Code