Skip to content

Commit e4cc00a

Browse files
committed
fix: terminal component does not restart if given different extraEnv
1 parent b51bfc4 commit e4cc00a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

plugins/plugin-codeflare/src/controller/terminal.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ type State = Partial<Pick<BaseProps, "cmdline" | "env">> & {
8181
/** Use this guidebook in the terminal execution */
8282
guidebook?: string
8383

84+
/** Any extra env vars to add to the guidebook execution. These will be pre-joined with the default env. */
85+
extraEnv?: BaseProps["env"]
86+
8487
/** Run guidebook in non-interactive mode? */
8588
noninteractive?: boolean
8689

@@ -131,7 +134,7 @@ export class TaskTerminal extends React.PureComponent<Props, State> {
131134
this.setState((curState) => ({
132135
cmdline,
133136
initCount: curState.initCount + 1,
134-
env: Object.assign({}, env, { MWCLEAR_INITIAL: "true" }, this.props.extraEnv),
137+
env: Object.assign({}, env, { MWCLEAR_INITIAL: "true" }, this.state.extraEnv),
135138
}))
136139
} catch (error) {
137140
console.error("Error initializing command line", error)
@@ -156,13 +159,16 @@ export class TaskTerminal extends React.PureComponent<Props, State> {
156159
this.setState({ guidebook, ifor: true, noninteractive: false })
157160

158161
public static getDerivedStateFromProps(props: Props, state: State) {
159-
if (props.defaultGuidebook && state.guidebook !== props.defaultGuidebook) {
162+
if ((props.defaultGuidebook && state.guidebook !== props.defaultGuidebook) || props.extraEnv !== state.extraEnv) {
163+
// different guidebook or different env vars to be passed to that guidebook
160164
return {
161165
ifor: false,
166+
extraEnv: props.extraEnv,
162167
guidebook: props.defaultGuidebook,
163168
noninteractive: props.defaultNoninteractive,
164169
}
165170
} else if (props.defaultNoninteractive !== state.noninteractive) {
171+
// different interactivity
166172
return {
167173
ifor: false,
168174
noninteractive: props.defaultNoninteractive,

0 commit comments

Comments
 (0)