Fix mobile terminal tab routing and remount restoration
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user