Skip to content

Commit b621ba9

Browse files
fix(desktop): prevent double logging workspace actions
1 parent 0bd5c04 commit b621ba9

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

desktop/src/views/Pro/Workspace/Logs.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff 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 (

0 commit comments

Comments
 (0)