Skip to content

Commit 12ced58

Browse files
waleedlatif1claude
andcommitted
fix(table): prevent stale refs during column drag operations
Fix two bugs in column drag-and-drop: 1. Stale columnWidths ref during rename - compute updated widths inline before passing to updateMetadata 2. Escape-cancelled drag still reorders - update dropTargetColumnNameRef directly in handleColumnDragLeave to prevent handleColumnDragEnd from reading stale ref value Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ed1feca commit 12ced58

File tree

1 file changed

+8
-5
lines changed
  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table

1 file changed

+8
-5
lines changed

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,17 @@ export function Table({
360360
const columnRename = useInlineRename({
361361
onSave: (columnName, newName) => {
362362
pushUndoRef.current({ type: 'rename-column', oldName: columnName, newName })
363-
setColumnWidths((prev) => {
364-
if (!(columnName in prev)) return prev
365-
return { ...prev, [newName]: prev[columnName] }
366-
})
363+
let updatedWidths = columnWidthsRef.current
364+
if (columnName in updatedWidths) {
365+
const { [columnName]: width, ...rest } = updatedWidths
366+
updatedWidths = { ...rest, [newName]: width }
367+
setColumnWidths(updatedWidths)
368+
}
367369
const updatedOrder = columnOrderRef.current?.map((n) => (n === columnName ? newName : n))
368370
if (updatedOrder) {
369371
setColumnOrder(updatedOrder)
370372
updateMetadataRef.current({
371-
columnWidths: columnWidthsRef.current,
373+
columnWidths: updatedWidths,
372374
columnOrder: updatedOrder,
373375
})
374376
}
@@ -683,6 +685,7 @@ export function Table({
683685
}, [])
684686

685687
const handleColumnDragLeave = useCallback(() => {
688+
dropTargetColumnNameRef.current = null
686689
setDropTargetColumnName(null)
687690
}, [])
688691

0 commit comments

Comments
 (0)