@@ -57,14 +57,20 @@ type CompassShellProps = {
5757 initialInput ?: string ;
5858} ;
5959
60- function useInitialEval ( initialEvaluate ?: string | string [ ] ) {
60+ function useInitialEval (
61+ initialEvaluate : string | string [ ] | undefined ,
62+ isRender : boolean
63+ ) {
6164 const [ initialEvalApplied , setInitialEvalApplied ] = useTabState (
6265 'initialEvalApplied' ,
6366 false
6467 ) ;
6568 useEffect ( ( ) => {
66- setInitialEvalApplied ( true ) ;
67- } , [ setInitialEvalApplied ] ) ;
69+ // as soon as we render the first time, set it to true
70+ if ( isRender && ! initialEvalApplied ) {
71+ setInitialEvalApplied ( true ) ;
72+ }
73+ } , [ initialEvalApplied , setInitialEvalApplied , isRender ] ) ;
6874 return initialEvalApplied ? undefined : initialEvaluate ;
6975}
7076
@@ -75,14 +81,19 @@ export const CompassShell: React.FC<CompassShellProps> = ({
7581 initialEvaluate : _initialEvaluate ,
7682 initialInput,
7783} ) => {
84+ const enableShell = usePreference ( 'enableShell' ) ;
85+ const canRenderShell = ! ! ( enableShell && initialHistory && runtime ) ;
86+
87+ // initialEvaluate will only be set on the first render
88+ const initialEvaluate = useInitialEval ( _initialEvaluate , canRenderShell ) ;
89+
7890 const editorRef = useRef < EditorRef > ( null ) ;
79- const initialEvaluate = useInitialEval ( _initialEvaluate ) ;
91+
8092 const [ isOperationInProgress , setIsOperationInProgress ] = useTabState (
8193 'isOperationInProgress' ,
8294 false
8395 ) ;
8496
85- const enableShell = usePreference ( 'enableShell' ) ;
8697 const [ infoModalVisible , setInfoModalVisible ] = useState ( false ) ;
8798 const [ shellOutput , setShellOutput ] = useTabState < ShellOutputEntry [ ] > (
8899 'shellOutput' ,
@@ -121,13 +132,13 @@ export const CompassShell: React.FC<CompassShellProps> = ({
121132 setIsOperationInProgress ( false ) ;
122133 } , [ setIsOperationInProgress ] ) ;
123134
124- const canRenderShell = enableShell && initialHistory && runtime ;
125-
126135 useEffect ( ( ) => {
127- return rafraf ( ( ) => {
128- editorRef . current ?. focus ( ) ;
129- } ) ;
130- } , [ ] ) ;
136+ if ( canRenderShell ) {
137+ return rafraf ( ( ) => {
138+ editorRef . current ?. focus ( ) ;
139+ } ) ;
140+ }
141+ } , [ canRenderShell ] ) ;
131142
132143 if ( ! enableShell ) {
133144 return (
0 commit comments