Skip to content

Commit 22c37ef

Browse files
fix(table): roll back optimistic run counter when no dispatch is created
useRunColumn.onSuccess returned early on a null dispatchId (no matching groups / eligible rows) without undoing the onMutate counter bump — and no SSE would arrive to correct it, leaving the counter permanently inflated. Restore the pre-mutation run-state on that path, mirroring onError.
1 parent 248839e commit 22c37ef

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

apps/sim/hooks/queries/tables.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,14 +1410,22 @@ export function useRunColumn({ workspaceId, tableId }: RowMutationContext) {
14101410
queryClient.setQueryData(tableKeys.activeDispatches(tableId), context.runStateSnapshot)
14111411
}
14121412
},
1413-
onSuccess: (data, { groupIds, runMode = 'all', rowIds }) => {
1413+
onSuccess: (data, { groupIds, runMode = 'all', rowIds }, context) => {
14141414
// Seed the dispatch into the overlay list (drives resolveCellExec's
14151415
// queued overlay for ahead-of-cursor rows). Upsert directly from the
14161416
// response instead of refetching — a refetch would reset the
14171417
// optimistic counter to the server's still-zero count (the dispatcher
14181418
// hasn't stamped cells yet).
14191419
const dispatchId = data?.data?.dispatchId
1420-
if (!dispatchId) return
1420+
if (!dispatchId) {
1421+
// No dispatch was created (e.g. no matching groups / eligible rows).
1422+
// No SSE will arrive to reconcile the optimistic counter bump, so roll
1423+
// it back to its pre-mutation value.
1424+
if (context?.didBumpRunState) {
1425+
queryClient.setQueryData(tableKeys.activeDispatches(tableId), context.runStateSnapshot)
1426+
}
1427+
return
1428+
}
14211429
queryClient.setQueryData<TableRunState>(tableKeys.activeDispatches(tableId), (prev) => {
14221430
const base = prev ?? { dispatches: [], runningCellCount: 0, runningByRowId: {} }
14231431
if (base.dispatches.some((d) => d.id === dispatchId)) return base

0 commit comments

Comments
 (0)