@@ -208,6 +208,9 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
208208
209209 const editorRef = useRef < EditorRef | null > ( null ) ;
210210 const shellInputContainerRef = useRef < HTMLDivElement > ( null ) ;
211+ const initialEvaluateRef = useRef ( initialEvaluate ) ;
212+ const outputRef = useRef ( output ) ;
213+ const historyRef = useRef ( history ) ;
211214
212215 useImperativeHandle (
213216 ref ,
@@ -256,7 +259,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
256259 return {
257260 onPrint : ( result : RuntimeEvaluationResult [ ] ) : void => {
258261 const newOutput = [
259- ...( output ?? [ ] ) ,
262+ ...( outputRef . current ?? [ ] ) ,
260263 ...result . map (
261264 ( entry ) : ShellOutputEntry => ( {
262265 format : 'output' ,
@@ -267,6 +270,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
267270 ] ;
268271
269272 capLengthEnd ( newOutput , maxOutputLength ) ;
273+ outputRef . current = newOutput ;
270274 onOutputChanged ?.( newOutput ) ;
271275 } ,
272276 onPrompt : async (
@@ -300,10 +304,11 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
300304 return ret ;
301305 } ,
302306 onClearCommand : ( ) : void => {
307+ outputRef . current = [ ] ;
303308 onOutputChanged ?.( [ ] ) ;
304309 } ,
305310 } ;
306- } , [ focusEditor , maxOutputLength , onOutputChanged , output ] ) ;
311+ } , [ focusEditor , maxOutputLength , onOutputChanged ] ) ;
307312
308313 const updateShellPrompt = useCallback ( async ( ) : Promise < void > => {
309314 let newShellPrompt = '>' ;
@@ -370,8 +375,8 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
370375
371376 const onInput = useCallback (
372377 async ( code : string ) => {
373- const newOutput = [ ...( output ?? [ ] ) ] ;
374- const newHistory = [ ...( history ?? [ ] ) ] ;
378+ const newOutput = [ ...( outputRef . current ?? [ ] ) ] ;
379+ const newHistory = [ ...( historyRef . current ?? [ ] ) ] ;
375380
376381 // don't evaluate empty input, but do add it to the output
377382 if ( ! code || code . trim ( ) === '' ) {
@@ -380,6 +385,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
380385 value : ' ' ,
381386 } ) ;
382387 capLengthEnd ( newOutput , maxOutputLength ) ;
388+ outputRef . current = newOutput ;
383389 onOutputChanged ?.( newOutput ) ;
384390 return ;
385391 }
@@ -390,13 +396,15 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
390396 value : code ,
391397 } ) ;
392398 capLengthEnd ( newOutput , maxOutputLength ) ;
399+ outputRef . current = newOutput ;
393400 onOutputChanged ?.( newOutput ) ;
394401
395402 const outputLine = await evaluate ( code ) ;
396403
397404 // add output to output
398405 newOutput . push ( outputLine ) ;
399406 capLengthEnd ( newOutput , maxOutputLength ) ;
407+ outputRef . current = newOutput ;
400408 onOutputChanged ?.( newOutput ) ;
401409
402410 // update history
@@ -406,11 +414,10 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
406414 newHistory ,
407415 redactInfo ? 'redact-sensitive-data' : 'keep-sensitive-data'
408416 ) ;
417+ historyRef . current = newHistory ;
409418 onHistoryChanged ?.( newHistory ) ;
410419 } ,
411420 [
412- output ,
413- history ,
414421 onOutputChanged ,
415422 evaluate ,
416423 redactInfo ,
@@ -450,16 +457,8 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
450457 return Promise . resolve ( false ) ;
451458 } , [ isOperationInProgress , runtime ] ) ;
452459
453- const [ isFirstRun , setIsFirstRun ] = useState ( true ) ;
454-
455460 useEffect ( ( ) => {
456- if ( ! isFirstRun ) {
457- return ;
458- }
459-
460- setIsFirstRun ( false ) ;
461-
462- const evalLines = normalizeInitialEvaluate ( initialEvaluate ) ;
461+ const evalLines = normalizeInitialEvaluate ( initialEvaluateRef . current ) ;
463462 if ( evalLines . length ) {
464463 void ( async ( ) => {
465464 for ( const input of evalLines ) {
@@ -469,7 +468,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
469468 } else {
470469 void updateShellPrompt ( ) ;
471470 }
472- } , [ initialEvaluate , isFirstRun , onInput , updateShellPrompt ] ) ;
471+ } , [ onInput , updateShellPrompt ] ) ;
473472
474473 useEffect ( ( ) => {
475474 rafraf ( ( ) => {
0 commit comments