Skip to content

Commit 45d46d9

Browse files
committed
fix(table): clean up cell refs on unmount and guard Enter advance
- delete inputRefs/overlayRefs entries when a cell detaches so deleting a row can't leave stale position-keyed entries - guard Enter advance with isConnected so a stale ref can never steal focus into a detached node
1 parent aa413a4 commit 45d46d9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/table

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/table/table.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ function TableCell({
122122
}
123123
const nextCellKey = `${rowIndex + 1}-${column}`
124124
const nextInput = inputRefs.current.get(nextCellKey)
125-
if (nextInput) {
125+
// `isConnected` guards against a stale ref: position-keyed entries can
126+
// outlive a deleted row, and focusing a detached node would steal focus
127+
// from the current cell. A real next row's input is always connected.
128+
if (nextInput?.isConnected) {
126129
e.preventDefault()
127130
nextInput.focus()
128131
inputController.fieldHelpers.hideFieldDropdowns(nextCellKey)
@@ -170,6 +173,7 @@ function TableCell({
170173
<input
171174
ref={(el) => {
172175
if (el) inputRefs.current.set(cellKey, el)
176+
else inputRefs.current.delete(cellKey)
173177
}}
174178
type='text'
175179
value={cellValue}
@@ -190,6 +194,7 @@ function TableCell({
190194
<div
191195
ref={(el) => {
192196
if (el) overlayRefs.current.set(cellKey, el)
197+
else overlayRefs.current.delete(cellKey)
193198
}}
194199
data-overlay={cellKey}
195200
className='scrollbar-hide pointer-events-none absolute top-0 right-[10px] bottom-0 left-[10px] overflow-x-auto overflow-y-hidden bg-transparent'

0 commit comments

Comments
 (0)