Fix mobile terminal tab routing and remount restoration

This commit is contained in:
Mohamed Boudra
2026-02-25 20:05:23 +07:00
parent 91634ca6f2
commit c0420ac1f9
3 changed files with 185 additions and 9 deletions
@@ -57,6 +57,7 @@ export default function TerminalEmulator({
const rootRef = useRef<HTMLDivElement | null>(null);
const hostRef = useRef<HTMLDivElement | null>(null);
const runtimeRef = useRef<TerminalEmulatorRuntime | null>(null);
const appliedInitialOutputRef = useRef<string | null>(null);
useEffect(() => {
const host = hostRef.current;
@@ -86,15 +87,34 @@ export default function TerminalEmulator({
cursorColor,
},
});
appliedInitialOutputRef.current = initialOutputText;
return () => {
runtime.unmount();
if (runtimeRef.current === runtime) {
runtimeRef.current = null;
}
appliedInitialOutputRef.current = null;
};
}, [backgroundColor, cursorColor, foregroundColor, streamKey]);
useEffect(() => {
const runtime = runtimeRef.current;
if (!runtime) {
return;
}
if (appliedInitialOutputRef.current === initialOutputText) {
return;
}
appliedInitialOutputRef.current = initialOutputText;
runtime.clear();
if (initialOutputText.length > 0) {
runtime.write({ text: initialOutputText });
}
}, [initialOutputText]);
useEffect(() => {
runtimeRef.current?.setCallbacks({
callbacks: {