@@ -172,27 +172,44 @@ export function DeployModal({
172172 // Convert blockId_attribute format to blockName.attribute format for display
173173 const UUID_REGEX = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } / i
174174
175- const convertedOutputs = selectedStreamingOutputs . map ( ( outputId ) => {
176- // If it starts with a UUID, convert to blockName.attribute format
177- if ( UUID_REGEX . test ( outputId ) ) {
178- const underscoreIndex = outputId . indexOf ( '_' )
179- if ( underscoreIndex === - 1 ) return outputId
180-
181- const blockId = outputId . substring ( 0 , underscoreIndex )
182- const attribute = outputId . substring ( underscoreIndex + 1 )
183-
184- // Find the block by ID and get its name
185- const block = blocks . find ( ( b ) => b . id === blockId )
186- if ( block ?. name ) {
187- // Normalize block name: lowercase and remove spaces
188- const normalizedBlockName = block . name . toLowerCase ( ) . replace ( / \s + / g, '' )
189- return `${ normalizedBlockName } .${ attribute } `
175+ const convertedOutputs = selectedStreamingOutputs
176+ . map ( ( outputId ) => {
177+ // If it starts with a UUID, convert to blockName.attribute format
178+ if ( UUID_REGEX . test ( outputId ) ) {
179+ const underscoreIndex = outputId . indexOf ( '_' )
180+ if ( underscoreIndex === - 1 ) return null
181+
182+ const blockId = outputId . substring ( 0 , underscoreIndex )
183+ const attribute = outputId . substring ( underscoreIndex + 1 )
184+
185+ // Find the block by ID and get its name
186+ const block = blocks . find ( ( b ) => b . id === blockId )
187+ if ( block ?. name ) {
188+ // Normalize block name: lowercase and remove spaces
189+ const normalizedBlockName = block . name . toLowerCase ( ) . replace ( / \s + / g, '' )
190+ return `${ normalizedBlockName } .${ attribute } `
191+ }
192+ // Block not found (deleted), return null to filter out
193+ return null
190194 }
191- }
192195
193- // Already in blockName.attribute format or couldn't convert
194- return outputId
195- } )
196+ // Already in blockName.attribute format, verify the block exists
197+ const parts = outputId . split ( '.' )
198+ if ( parts . length >= 2 ) {
199+ const blockName = parts [ 0 ]
200+ // Check if a block with this name exists
201+ const block = blocks . find (
202+ ( b ) => b . name ?. toLowerCase ( ) . replace ( / \s + / g, '' ) === blockName . toLowerCase ( )
203+ )
204+ if ( ! block ) {
205+ // Block not found (deleted), return null to filter out
206+ return null
207+ }
208+ }
209+
210+ return outputId
211+ } )
212+ . filter ( ( output ) : output is string => output !== null )
196213
197214 exampleData . selectedOutputs = convertedOutputs
198215 }
@@ -385,6 +402,43 @@ export function DeployModal({
385402 }
386403 } , [ open , workflowId ] )
387404
405+ // Clean up selectedStreamingOutputs when blocks are deleted
406+ useEffect ( ( ) => {
407+ if ( ! open || selectedStreamingOutputs . length === 0 ) return
408+
409+ const blocks = Object . values ( useWorkflowStore . getState ( ) . blocks )
410+ const UUID_REGEX = / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } / i
411+
412+ const validOutputs = selectedStreamingOutputs . filter ( ( outputId ) => {
413+ // If it starts with a UUID, extract the blockId and check if the block exists
414+ if ( UUID_REGEX . test ( outputId ) ) {
415+ const underscoreIndex = outputId . indexOf ( '_' )
416+ if ( underscoreIndex === - 1 ) return false
417+
418+ const blockId = outputId . substring ( 0 , underscoreIndex )
419+ const block = blocks . find ( ( b ) => b . id === blockId )
420+ return ! ! block
421+ }
422+
423+ // If it's in blockName.attribute format, check if a block with that name exists
424+ const parts = outputId . split ( '.' )
425+ if ( parts . length >= 2 ) {
426+ const blockName = parts [ 0 ]
427+ const block = blocks . find (
428+ ( b ) => b . name ?. toLowerCase ( ) . replace ( / \s + / g, '' ) === blockName . toLowerCase ( )
429+ )
430+ return ! ! block
431+ }
432+
433+ return true
434+ } )
435+
436+ // Update the state if any outputs were filtered out
437+ if ( validOutputs . length !== selectedStreamingOutputs . length ) {
438+ setSelectedStreamingOutputs ( validOutputs )
439+ }
440+ } , [ open , selectedStreamingOutputs , setSelectedStreamingOutputs ] )
441+
388442 const handleActivateVersion = ( version : number ) => {
389443 setVersionToActivate ( version )
390444 setActiveTab ( 'api' )
0 commit comments