From ec093a01bf5255700738c591f6d8bb31572edb9f Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Fri, 5 Jul 2024 14:21:38 +0200 Subject: [PATCH] fix(browser-repl): make sure we are actually using initial value of initialEvaluate --- packages/browser-repl/src/components/shell.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/browser-repl/src/components/shell.tsx b/packages/browser-repl/src/components/shell.tsx index b407ae032b..0ac515dff1 100644 --- a/packages/browser-repl/src/components/shell.tsx +++ b/packages/browser-repl/src/components/shell.tsx @@ -162,15 +162,18 @@ export class Shell extends Component { }; componentDidMount(): void { + // Store the intial prop value on mount so that we're not using potentially + // updated one when actually running the lines + let evalLines: string[] = []; + if (this.props.initialEvaluate) { + evalLines = Array.isArray(this.props.initialEvaluate) + ? this.props.initialEvaluate + : [this.props.initialEvaluate]; + } this.scrollToBottom(); void this.updateShellPrompt().then(async () => { - if (this.props.initialEvaluate) { - const evalLines = Array.isArray(this.props.initialEvaluate) - ? this.props.initialEvaluate - : [this.props.initialEvaluate]; - for (const input of evalLines) { - await this.onInput(input); - } + for (const input of evalLines) { + await this.onInput(input); } }); }