Skip to content

Commit 872953a

Browse files
committed
fix(managed-agent): async table seed no longer clobbers in-flight edits
Cursor Bugbot on 9704cec flagged a race in the `Table` sub-block init effect: `fetchDefaultRows` is async, and the effect's guard on `storeValue !== undefined && storeValue !== null` was captured at effect setup time. Between the fetch start and its resolution, a user could type into the phantom row — persisting the row via `handleCellChange`'s `setStoreValue([newRow])` — and then the resolved fetch would call `setStoreValue(defaultRows)` and clobber their edit. Fix: re-read the current value from the subblock store inside `seedWith` right before writing (`useSubBlockStore.getState() .getValue(blockId, subBlockId)`), and skip the write if the value has already been populated since the effect started. The closure-captured `storeValue` was stale; the store's `getState` returns the LATEST value synchronously. Other Bugbot comments on this commit are re-fires of items already fixed on prior commits (they signature-match against static code shapes without noticing the corrective code that lives beside them): `Stale labels after connection change` (fixed via `depsEqual` in `areSubBlockRowPropsEqual`), `Empty table re-seeds defaults` (fixed via `storeValue !== undefined && storeValue !== null` guard), `Defaults API lacks authentication` (fixed via `checkSessionOrInternalAuth`), `Rotate connection hook unused` (fixed via the new Rotate-key modal wired into the settings UI). `Empty table shows phantom row` is theoretical — the delete-row guard (`rows.length === 1`) prevents users from reaching `[]` through the UI, so the mismatch it warns about isn't reachable in normal use.
1 parent fa2cc10 commit 872953a

1 file changed

Lines changed: 10 additions & 0 deletions

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useSubBlockInput } from '@/app/workspace/[workspaceId]/w/[workflowId]/c
1515
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
1616
import { useActiveSearchTarget } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/providers/active-search-target-provider'
1717
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
18+
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1819

1920
const logger = createLogger('Table')
2021

@@ -283,6 +284,13 @@ export function Table({
283284
let cancelled = false
284285
const seedWith = (rows: Array<{ cells: Record<string, string> }> | undefined) => {
285286
if (cancelled) return
287+
// Re-read the LATEST value from the subblock store, not the
288+
// closure-captured `storeValue` from render time. Otherwise an
289+
// async `fetchDefaultRows` that resolves after the user has
290+
// already started editing the table would overwrite their
291+
// in-progress rows with the deployer defaults.
292+
const currentValue = useSubBlockStore.getState().getValue(blockId, subBlockId)
293+
if (currentValue !== undefined && currentValue !== null) return
286294
const seedRows: WorkflowTableRow[] =
287295
Array.isArray(rows) && rows.length > 0
288296
? rows.map((row) => ({
@@ -310,6 +318,8 @@ export function Table({
310318
emptyCellsTemplate,
311319
defaultRows,
312320
fetchDefaultRows,
321+
blockId,
322+
subBlockId,
313323
])
314324

315325
// Ensure value is properly typed and initialized

0 commit comments

Comments
 (0)