Skip to content

Commit

Permalink
fix initial evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed Dec 12, 2024
1 parent aec4757 commit 15b54e9
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@ type CompassShellProps = {
initialInput?: string;
};

function useInitialEval(initialEvaluate?: string | string[]) {
function useInitialEval(
initialEvaluate: string | string[] | undefined,
isRender: boolean
) {
const [initialEvalApplied, setInitialEvalApplied] = useTabState(
'initialEvalApplied',
false
);
useEffect(() => {
setInitialEvalApplied(true);
}, [setInitialEvalApplied]);
// as soon as we render the first time, set it to true
if (isRender && !initialEvalApplied) {
setInitialEvalApplied(true);
}
}, [initialEvalApplied, setInitialEvalApplied, isRender]);
return initialEvalApplied ? undefined : initialEvaluate;
}

Expand All @@ -75,14 +81,19 @@ export const CompassShell: React.FC<CompassShellProps> = ({
initialEvaluate: _initialEvaluate,
initialInput,
}) => {
const enableShell = usePreference('enableShell');
const canRenderShell = !!(enableShell && initialHistory && runtime);

// initialEvaluate will only be set on the first render
const initialEvaluate = useInitialEval(_initialEvaluate, canRenderShell);

const editorRef = useRef<EditorRef>(null);
const initialEvaluate = useInitialEval(_initialEvaluate);

const [isOperationInProgress, setIsOperationInProgress] = useTabState(
'isOperationInProgress',
false
);

const enableShell = usePreference('enableShell');
const [infoModalVisible, setInfoModalVisible] = useState(false);
const [shellOutput, setShellOutput] = useTabState<ShellOutputEntry[]>(
'shellOutput',
Expand Down Expand Up @@ -121,13 +132,13 @@ export const CompassShell: React.FC<CompassShellProps> = ({
setIsOperationInProgress(false);
}, [setIsOperationInProgress]);

const canRenderShell = enableShell && initialHistory && runtime;

useEffect(() => {
return rafraf(() => {
editorRef.current?.focus();
});
}, []);
if (canRenderShell) {
return rafraf(() => {
editorRef.current?.focus();
});
}
}, [canRenderShell]);

if (!enableShell) {
return (
Expand Down

0 comments on commit 15b54e9

Please sign in to comment.