Skip to content

Commit 2197113

Browse files
committed
address bugbot comments
1 parent 09dd870 commit 2197113

File tree

1 file changed

+16
-2
lines changed
  • apps/sim/stores/terminal/console

1 file changed

+16
-2
lines changed

apps/sim/stores/terminal/console/store.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,28 @@ function appendWorkflowEntry(
226226
trimmedEntries: ConsoleEntry[]
227227
): Pick<ConsoleStore, 'workflowEntries' | 'entryIdsByBlockExecution' | 'entryLocationById'> {
228228
const workflowEntries = cloneWorkflowEntries(state.workflowEntries)
229+
const previousEntries = workflowEntries[workflowId] ?? EMPTY_CONSOLE_ENTRIES
229230
workflowEntries[workflowId] = trimmedEntries
230231

231232
const entryLocationById = { ...state.entryLocationById }
232233
const entryIdsByBlockExecution = { ...state.entryIdsByBlockExecution }
233234

235+
const survivingIds = new Set(trimmedEntries.map((e) => e.id))
236+
const droppedEntries = previousEntries.filter((e) => !survivingIds.has(e.id))
237+
if (droppedEntries.length > 0) {
238+
removeWorkflowIndexes(workflowId, droppedEntries, entryIdsByBlockExecution, entryLocationById)
239+
}
240+
234241
trimmedEntries.forEach((entry, index) => {
235242
entryLocationById[entry.id] = { workflowId, index }
236243
})
237244

238245
const blockExecutionKey = getBlockExecutionKey(newEntry.blockId, newEntry.executionId)
239246
const existingIds = entryIdsByBlockExecution[blockExecutionKey]
240247
if (existingIds) {
241-
entryIdsByBlockExecution[blockExecutionKey] = [...existingIds, newEntry.id]
248+
if (!existingIds.includes(newEntry.id)) {
249+
entryIdsByBlockExecution[blockExecutionKey] = [...existingIds, newEntry.id]
250+
}
242251
} else {
243252
entryIdsByBlockExecution[blockExecutionKey] = [newEntry.id]
244253
}
@@ -746,6 +755,11 @@ export function useConsoleEntry(entryId?: string | null): ConsoleEntry | null {
746755
return null
747756
}
748757

749-
return state.workflowEntries[location.workflowId]?.[location.index] ?? null
758+
const entry = state.workflowEntries[location.workflowId]?.[location.index]
759+
if (!entry || entry.id !== entryId) {
760+
return null
761+
}
762+
763+
return entry
750764
})
751765
}

0 commit comments

Comments
 (0)