Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 7eb69fb

Browse files
myan9starpit
authored andcommitted
fix(plugins/plugin-client-common): clicking 'remove' of a watchable response doesn't abort the underlying pty job
Fixes #5090
1 parent 4daba1f commit 7eb69fb

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

plugins/plugin-client-common/src/components/Views/Terminal/ScrollableTerminal.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
Cancelled,
4343
Processing,
4444
isActive,
45+
isOk,
4546
isProcessing,
4647
hasUUID,
4748
BlockModel
@@ -529,6 +530,13 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
529530
return !this.hasPinned(curState.splits[availableSplit]) ? availableSplit : 0
530531
}
531532

533+
// If the block has watchable response, abort the job
534+
private removeWatchableBlock(block: BlockModel) {
535+
if (isOk(block) && isWatchable(block.response)) {
536+
block.response.watch.abort()
537+
}
538+
}
539+
532540
/**
533541
* Remove the given split (identified by `sbuuid`) from the state.
534542
*
@@ -537,6 +545,8 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
537545
this.setState(curState => {
538546
const idx = this.findSplit(this.state, sbuuid)
539547
if (idx >= 0) {
548+
curState.splits[idx].blocks.forEach(this.removeWatchableBlock)
549+
540550
const splits = curState.splits.slice(0, idx).concat(curState.splits.slice(idx + 1))
541551

542552
if (splits.length === 0) {
@@ -604,12 +614,16 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
604614

605615
/** remove the block at the given index */
606616
private willRemoveBlock(uuid: string, idx: number) {
607-
this.splice(uuid, curState => ({
608-
blocks: curState.blocks
609-
.slice(0, idx)
610-
.concat(curState.blocks.slice(idx + 1))
611-
.concat(curState.blocks.find(_ => isActive(_)) ? [] : [Active()]) // plus a new block, if needed
612-
}))
617+
this.splice(uuid, curState => {
618+
this.removeWatchableBlock(curState.blocks[idx])
619+
620+
return {
621+
blocks: curState.blocks
622+
.slice(0, idx)
623+
.concat(curState.blocks.slice(idx + 1))
624+
.concat(curState.blocks.find(_ => isActive(_)) ? [] : [Active()]) // plus a new block, if needed
625+
}
626+
})
613627
}
614628

615629
private tabRefFor(scrollback: ScrollbackState, ref: HTMLElement) {

0 commit comments

Comments
 (0)