Skip to content

Commit 633ddba

Browse files
waleedlatif1claude
andcommitted
fix(tables): guard rowId remap effect and document paste batch position
- Skip the validation effect when rows is empty (transient state during initial load of a new sort/filter before keepPreviousData populates) so selection survives uncached query changes. - Skip when isColumnSelection is true; the column-selection pinning effect owns focus.rowIndex for those, and remapping would shrink a full-column range to wherever the captured endpoints happened to land after reorder. - Comment lastRowPosition's hoist invariant so a future refactor doesn't move it inside the loop and produce colliding positions. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1287623 commit 633ddba

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,14 @@ export function Table({
11601160
}, [selectionFocus])
11611161

11621162
useEffect(() => {
1163+
// Skip during transient empty-rows state (initial load of a new sort/filter
1164+
// before keepPreviousData kicks in) — clearing here would lose the user's
1165+
// selection across every uncached query change.
1166+
if (rows.length === 0) return
1167+
// Column selections pin focus to the last row via the effect above; remapping
1168+
// by row id would shrink a full-column range to whichever rows happened to be
1169+
// at the endpoints when the selection was captured.
1170+
if (isColumnSelectionRef.current) return
11631171
const anchor = selectionAnchorRef.current
11641172
if (anchor) {
11651173
const expectedId = anchorRowIdRef.current
@@ -1799,6 +1807,8 @@ export function Table({
17991807

18001808
const currentCols = columnsRef.current
18011809
const currentRows = rowsRef.current
1810+
// Captured once before the loop so each new row in the batch gets a unique,
1811+
// sequential position via `+ (newRowIndex - currentRows.length)` below.
18021812
const lastRowPosition = currentRows.reduce((max, r) => Math.max(max, r.position), -1)
18031813

18041814
const undoCells: Array<{ rowId: string; data: Record<string, unknown> }> = []

0 commit comments

Comments
 (0)