@@ -202,6 +202,10 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
202202 const darkMode = useDarkMode ( ) ;
203203
204204 const editorRef = useRef < EditorRef | null > ( null ) ;
205+ const outputRef = useRef ( output ) ;
206+ const historyRef = useRef ( history ) ;
207+ const shellInputContainerRef = useRef < HTMLDivElement > ( null ) ;
208+ const initialEvaluateRef = useRef ( initialEvaluate ) ;
205209
206210 useImperativeHandle (
207211 ref ,
@@ -233,8 +237,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
233237 [ ]
234238 ) ;
235239
236- const shellInputContainerRef = useRef < HTMLDivElement > ( null ) ;
237-
238240 const [ passwordPrompt , setPasswordPrompt ] = useState ( '' ) ;
239241 const [ shellPrompt , setShellPrompt ] = useState ( '>' ) ;
240242 const [ onFinishPasswordPrompt , setOnFinishPasswordPrompt ] = useState <
@@ -252,7 +254,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
252254 return {
253255 onPrint : ( result : RuntimeEvaluationResult [ ] ) : void => {
254256 const newOutput = [
255- ...( output ?? [ ] ) ,
257+ ...( outputRef . current ?? [ ] ) ,
256258 ...result . map (
257259 ( entry ) : ShellOutputEntry => ( {
258260 format : 'output' ,
@@ -299,7 +301,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
299301 onOutputChanged ?.( [ ] ) ;
300302 } ,
301303 } ;
302- } , [ focusEditor , maxOutputLength , onOutputChanged , output ] ) ;
304+ } , [ focusEditor , maxOutputLength , onOutputChanged ] ) ;
303305
304306 const updateShellPrompt = useCallback ( async ( ) : Promise < void > => {
305307 let newShellPrompt = '>' ;
@@ -366,8 +368,8 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
366368
367369 const onInput = useCallback (
368370 async ( code : string ) => {
369- const newOutput = [ ...( output ?? [ ] ) ] ;
370- const newHistory = [ ...( history ?? [ ] ) ] ;
371+ const newOutput = [ ...( outputRef . current ?? [ ] ) ] ;
372+ const newHistory = [ ...( historyRef . current ?? [ ] ) ] ;
371373
372374 // don't evaluate empty input, but do add it to the output
373375 if ( ! code || code . trim ( ) === '' ) {
@@ -405,8 +407,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
405407 onHistoryChanged ?.( newHistory ) ;
406408 } ,
407409 [
408- output ,
409- history ,
410410 onOutputChanged ,
411411 evaluate ,
412412 redactInfo ,
@@ -446,11 +446,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
446446 return Promise . resolve ( false ) ;
447447 } , [ isOperationInProgress , runtime ] ) ;
448448
449- const initialEvaluateRef = useRef ( initialEvaluate ) ;
450-
451449 useEffect ( ( ) => {
452- scrollToBottom ( ) ;
453-
454450 void updateShellPrompt ( ) . then ( async ( ) => {
455451 if ( initialEvaluateRef . current ) {
456452 const evalLines = normalizeInitialEvaluate ( initialEvaluateRef . current ) ;
@@ -459,7 +455,11 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
459455 }
460456 }
461457 } ) ;
462- } , [ onInput , scrollToBottom , updateShellPrompt ] ) ;
458+ } , [ onInput , updateShellPrompt ] ) ;
459+
460+ useEffect ( ( ) => {
461+ scrollToBottom ( ) ;
462+ } ) ;
463463
464464 /* eslint-disable jsx-a11y/no-static-element-interactions */
465465 /* eslint-disable jsx-a11y/click-events-have-key-events */
0 commit comments