fix(web): only connect terminal ws when process is running
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { FitAddon } from "@xterm/addon-fit";
|
||||
import { Terminal } from "@xterm/xterm";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import { useProcessWebSocket } from "@/lib/api/process";
|
||||
import { useProcessStatus, useProcessWebSocket } from "@/lib/api/process";
|
||||
|
||||
interface TerminalPanelProps {
|
||||
workspaceId: string | null;
|
||||
@@ -16,7 +16,12 @@ export function TerminalPanel({ workspaceId }: TerminalPanelProps) {
|
||||
const isDeadRef = useRef(false);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [isDead, setIsDead] = useState(false);
|
||||
const { status, send, onData } = useProcessWebSocket(workspaceId);
|
||||
const { data: processStatus } = useProcessStatus(workspaceId);
|
||||
const processRunning = processStatus?.running === true;
|
||||
const { status, send, onData } = useProcessWebSocket(
|
||||
workspaceId,
|
||||
processRunning,
|
||||
);
|
||||
|
||||
// Initialize xterm once and keep it alive across WS status changes.
|
||||
useEffect(() => {
|
||||
@@ -148,11 +153,15 @@ export function TerminalPanel({ workspaceId }: TerminalPanelProps) {
|
||||
? "connecting…"
|
||||
: null;
|
||||
|
||||
const hint = processRunning
|
||||
? statusHint
|
||||
: "process not running — start it from the toolbar";
|
||||
|
||||
return (
|
||||
<section className="flex h-full w-full flex-col overflow-hidden bg-[#171717]">
|
||||
{statusHint && (
|
||||
{hint && (
|
||||
<div className="flex h-6 shrink-0 items-center px-2 text-[11px] text-muted-foreground">
|
||||
{statusHint}
|
||||
{hint}
|
||||
</div>
|
||||
)}
|
||||
<div ref={containerRef} className="min-h-0 flex-1 p-2" />
|
||||
|
||||
Reference in New Issue
Block a user