fix: 🐛 table column resize nan when headers reordered#908
Conversation
… but keep the same length. The useLayoutEffect was only watching headers.length, so column widths weren't recalculated when headers were reordered (as in EntitiesTable with column selection). Also fixed incorrect null check (-1 !== null) and added missing isSelectable dependencies to resize callbacks.
Replace fragile array-index based column width tracking with a Map using header labels as keys. This eliminates index synchronization bugs when columns are reordered, isSelectable changes, or new column types are added. - Change columnWidths from number[] to Map<string, number> - Store column labels in ResizeState instead of indices - Remove isSelectable dependencies from resize handlers - Position-agnostic width lookups prevent NaN on column reordering"
🦋 Changeset detectedLatest commit: 0c763f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Claude finished @punkbit's task in 1m 21s —— View job PR Review
The fix is well-reasoned and correctly solves the root cause. Switching from position-indexed arrays to a label-keyed 💡 Suggestions (non-blocking)
|
|
Claude finished @punkbit's task in 1m 29s —— View job PR Review
The fix is well-reasoned and correctly solves the root cause. Switching from position-indexed arrays to a label-keyed 💡 Suggestions (non-blocking)
|
📚 Storybook Preview Deployed✅ Preview URL: https://click-ppsrxzk80-clickhouse.vercel.app Built from commit: |
* fix: 🐛 Fixes resize breaking when column headers change order/content but keep the same length. The useLayoutEffect was only watching headers.length, so column widths weren't recalculated when headers were reordered (as in EntitiesTable with column selection). Also fixed incorrect null check (-1 !== null) and added missing isSelectable dependencies to resize callbacks. * refactor: Refactor Table column resize to use Map-based width storage Replace fragile array-index based column width tracking with a Map using header labels as keys. This eliminates index synchronization bugs when columns are reordered, isSelectable changes, or new column types are added. - Change columnWidths from number[] to Map<string, number> - Store column labels in ResizeState instead of indices - Remove isSelectable dependencies from resize handlers - Position-agnostic width lookups prevent NaN on column reordering" * chore: 🤖 add story with reordering control to test NaN fix * test: 💍 add story for testing reordering NaN * chore: 🤖 add changeset * chore: 🤖 lint amends * chore: 🤖 format * chore: 🤖 reset when headers change * fix: 🐛 NaN explicit intent, remove misleading key * fix: 🐛 remove width (unused) * fix: 🐛 remove dead guards * fix: 🐛 remove dead guards * fix: 🐛 inline dep * fix: 🐛 remove headers from deps * refactor: 💡 rename story
…937) * chore: 🤖 on v0.1.0.-rc.70 (updated with latest, dismissed previous history to avoid resolving conflicts and put back latest knowne rc version) * fix: 🐛 latest is actually *-rc.71 * chore: 🤖 release v0.1.0-rc.72 (rc) (#889) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * chore: 🤖 release v0.1.0-rc.73 (rc) (#893) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * chore: 🤖 release v0.1.0-rc.74 (rc) (#899) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * refactor: 💡 exposed asset names (revision 2) (#900) * refactor: 💡 rename assets * refactor: 💡 prefer planetscale * chore: 🤖 add changeset * refactor: 💡 normalise brand names * refactor: 💡 normalise names * chore: 🤖 release v0.1.0-rc.75 (rc) (#901) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * fix: 🐛 table column resize nan when headers reordered (#908) * fix: 🐛 Fixes resize breaking when column headers change order/content but keep the same length. The useLayoutEffect was only watching headers.length, so column widths weren't recalculated when headers were reordered (as in EntitiesTable with column selection). Also fixed incorrect null check (-1 !== null) and added missing isSelectable dependencies to resize callbacks. * refactor: Refactor Table column resize to use Map-based width storage Replace fragile array-index based column width tracking with a Map using header labels as keys. This eliminates index synchronization bugs when columns are reordered, isSelectable changes, or new column types are added. - Change columnWidths from number[] to Map<string, number> - Store column labels in ResizeState instead of indices - Remove isSelectable dependencies from resize handlers - Position-agnostic width lookups prevent NaN on column reordering" * chore: 🤖 add story with reordering control to test NaN fix * test: 💍 add story for testing reordering NaN * chore: 🤖 add changeset * chore: 🤖 lint amends * chore: 🤖 format * chore: 🤖 reset when headers change * fix: 🐛 NaN explicit intent, remove misleading key * fix: 🐛 remove width (unused) * fix: 🐛 remove dead guards * fix: 🐛 remove dead guards * fix: 🐛 inline dep * fix: 🐛 remove headers from deps * refactor: 💡 rename story * chore: 🤖 release v0.1.0-rc.76 (rc) (#909) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * chore: 🤖 release v0.1.0-rc.77 (rc) (#914) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * chore: 🤖 release v0.1.0-rc.78 (rc) (#921) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * chore: 🤖 remove a user's personal text editor (vscode) directory (#920) * chore: 🤖 remove user personal text-editor directory * chore: 🤖 add to .gitignore * chore: 🤖 split slack notifications (general vs pull requests)#919 * chore: 🤖 release v0.1.0-rc.79 (rc) (#927) Co-authored-by: punkbit <punkbit@users.noreply.github.com> * chore: 🤖 github actions maintenance (nodejs v20 action deprecation) (#922) * chore: 🤖 update step actions to use latest's * chore: 🤖 add deprecation note * fix: 🐛 missing imports file extension for dayjs in ESM environments (#933) * refactor: 💡 move days to date utils to help enforce extension for ESM consumer imports * chore: 🤖 add note and TODO * chore: 🤖 add changeset * chore: 🤖 release v0.1.0-rc.80 (rc) (#934) Co-authored-by: punkbit <236752+punkbit@users.noreply.github.com> * chore: 🤖 release v0.1.0 (stable) (#935) Co-authored-by: punkbit <236752+punkbit@users.noreply.github.com> --------- Co-authored-by: workflow-authentication-public[bot] <212800359+workflow-authentication-public[bot]@users.noreply.github.com> Co-authored-by: punkbit <punkbit@users.noreply.github.com> Co-authored-by: punkbit <236752+punkbit@users.noreply.github.com>
Why?
The
useLayoutEffectwatchingheaders.lengthwasn't triggered when headers were reordered (e.g., in sysadmin EntitiesTable with column selection), causing Column widths to be misaligned after reordering, NaN values appearing during resize operations and an incorrect null check that was always true.How?
Preview?
demo-table-reorder-resize-fix.mov