File tree Expand file tree Collapse file tree 1 file changed +37
-2
lines changed
desktop/src/views/Pro/Workspace Expand file tree Collapse file tree 1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -200,11 +200,46 @@ function ActionTerminal({ actionID }: TActionTerminalProps) {
200200 } = useStreamingTerminal ( { searchOptions, borderRadius : "none" } )
201201
202202 useEffect ( ( ) => {
203+ if ( ! action ) return
204+
205+ let isActive = true
203206 clearTerminal ( )
204207
205- return action ?. connectOrReplay ( ( e ) => {
206- connectStream ( e )
208+ // Create a new subscription with a delay for replay
209+ const setupStream = async ( ) => {
210+ if ( action . data . status === "pending" ) {
211+ // For pending actions, subscribe immediately
212+ return action . connectOrReplay ( ( e ) => {
213+ if ( isActive ) {
214+ connectStream ( e )
215+ }
216+ } )
217+ } else {
218+ // For completed actions, add a small delay to ensure cleanup
219+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
220+ if ( ! isActive ) return ( ) => { }
221+
222+ return action . connectOrReplay ( ( e ) => {
223+ if ( isActive ) {
224+ connectStream ( e )
225+ }
226+ } )
227+ }
228+ }
229+
230+ let cleanup : VoidFunction | void
231+ setupStream ( ) . then ( ( unsubscribe ) => {
232+ if ( isActive ) {
233+ cleanup = unsubscribe
234+ } else {
235+ unsubscribe ?.( )
236+ }
207237 } )
238+
239+ return ( ) => {
240+ isActive = false
241+ cleanup ?.( )
242+ }
208243 } , [ action , clearTerminal , connectStream ] )
209244
210245 return (
You can’t perform that action at this time.
0 commit comments