Skip to content

Commit

Permalink
Fix terminal repeatedly remounting on input
Browse files Browse the repository at this point in the history
  • Loading branch information
gingershaped committed Nov 11, 2024
1 parent bd8c908 commit 3da0b9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/latest/scripts/ui/Theseus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,18 @@ export function Theseus({ permalink }: TheseusProps) {
>
<VyTerminal
ref={runnerRef}
onRunningGroupChanged={(group) => {
onRunningGroupChanged={useCallback((group) => {
if (group != null) {
setState({ name: "running", group });
} else {
setState({ name: "idle" });
}
}}
onReady={() => {
}, [])}
onReady={useCallback(() => {
if (autorun) {
onRunClicked(null);
}
}}
}, [autorun, onRunClicked])}
/>
</Suspense>
</Tab.Pane>
Expand Down
9 changes: 7 additions & 2 deletions src/latest/scripts/ui/VyTerminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ const VyTerminal = forwardRef(function VyTerminal({ onRunningGroupChanged, onRea
});

useEffect(() => {
runner.attach(wrapperRef.current!);
runner.addEventListener("runningGroupChanged", runningGroupChangedCallback);
runner.addEventListener("ready", () => onReady?.() as void, { once: true });
return () => {
runner.detach();
runner.removeEventListener("runningGroupChanged", runningGroupChangedCallback);
};
}, [onReady, runner, runningGroupChangedCallback]);

useEffect(() => {
runner.attach(wrapperRef.current!);
return () => {
runner.detach();
};
}, [runner]);

return <div ref={wrapperRef} className="terminal-wrapper"></div>;
});
export default VyTerminal;

0 comments on commit 3da0b9c

Please sign in to comment.