@@ -152,7 +152,7 @@ function indexWorkflowEntries(
152152 const blockExecutionKey = getBlockExecutionKey ( entry . blockId , entry . executionId )
153153 const existingIds = entryIdsByBlockExecution [ blockExecutionKey ]
154154 if ( existingIds ) {
155- existingIds . push ( entry . id )
155+ entryIdsByBlockExecution [ blockExecutionKey ] = [ ... existingIds , entry . id ]
156156 } else {
157157 entryIdsByBlockExecution [ blockExecutionKey ] = [ entry . id ]
158158 }
@@ -474,22 +474,26 @@ export const useTerminalConsoleStore = create<ConsoleStore>()(
474474 return state
475475 }
476476
477- const workflowEntries = state . workflowEntries [ workflowId ] ?? EMPTY_CONSOLE_ENTRIES
477+ const currentEntries = state . workflowEntries [ workflowId ] ?? EMPTY_CONSOLE_ENTRIES
478+ let nextEntries : ConsoleEntry [ ] | null = null
478479
479480 for ( const candidateId of candidateIds ) {
480481 const location = state . entryLocationById [ candidateId ]
481482 if ( ! location || location . workflowId !== workflowId ) continue
482483
483- const entry = workflowEntries [ location . index ]
484+ const source = nextEntries ?? currentEntries
485+ const entry = source [ location . index ]
484486 if ( ! entry || entry . id !== candidateId ) continue
485487 if ( ! matchesEntryForUpdate ( entry , blockId , executionId , update ) ) continue
486488
489+ if ( ! nextEntries ) {
490+ nextEntries = [ ...currentEntries ]
491+ }
492+
487493 if ( typeof update === 'string' ) {
488494 const newOutput = normalizeConsoleOutput ( updateBlockOutput ( entry . output , update ) )
489- return patchWorkflowEntry ( state , workflowId , location . index , {
490- ...entry ,
491- output : newOutput ,
492- } )
495+ nextEntries [ location . index ] = { ...entry , output : newOutput }
496+ continue
493497 }
494498
495499 const updatedEntry = { ...entry }
@@ -588,10 +592,20 @@ export const useTerminalConsoleStore = create<ConsoleStore>()(
588592 updatedEntry . childWorkflowInstanceId = update . childWorkflowInstanceId
589593 }
590594
591- return patchWorkflowEntry ( state , workflowId , location . index , updatedEntry )
595+ nextEntries [ location . index ] = updatedEntry
592596 }
593597
594- return state
598+ if ( ! nextEntries ) {
599+ return state
600+ }
601+
602+ const workflowEntriesClone = cloneWorkflowEntries ( state . workflowEntries )
603+ workflowEntriesClone [ workflowId ] = nextEntries
604+ return {
605+ workflowEntries : workflowEntriesClone ,
606+ entryIdsByBlockExecution : state . entryIdsByBlockExecution ,
607+ entryLocationById : state . entryLocationById ,
608+ }
595609 } )
596610
597611 if ( typeof update === 'object' && update . error ) {
0 commit comments