()
| 384 | } |
| 385 | |
| 386 | export function RuntimeRoot() { |
| 387 | useSyncExternalStore(subscribeWorkspace, getWorkspaceGeneration); |
| 388 | useEffect(() => subscribeWorkspace(() => { |
| 389 | resetGlobalWorkspace(); |
| 390 | clearProjectWorkspaceCache(); |
| 391 | }), []); |
| 392 | const launchPlaceholder = useLocation({ select: (location) => location.pathname === "/remote-launch" }); |
| 393 | const [runtime, setRuntime] = useState<RuntimeInfo | null>(null); |
| 394 | const [error, setError] = useState<string | null>(null); |
| 395 | const everConnected = useRef(false); |
| 396 | const workspaceMounted = useRef(false); |
| 397 | const preferencesApplied = useRef(false); |
| 398 | const previousWorkspace = useRef<string | null>(null); |
| 399 | const [retriedInteractiveError, setRetriedInteractiveError] = useState<string | null>(null); |
| 400 | |
| 401 | const runtimeQuery = useQuery({ |
| 402 | ...getRuntimeQuery(), |
| 403 | enabled: !launchPlaceholder, |
| 404 | refetchInterval: (query) => query.state.status === "error" || query.state.data?.kind === "ssh" ? 2_000 : false, |
| 405 | refetchIntervalInBackground: true, |
| 406 | }); |
| 407 | useEffect(() => { |
| 408 | if (launchPlaceholder) return; |
| 409 | const next = runtimeQuery.data; |
| 410 | if (!next) { |
| 411 | setError(runtimeQuery.error?.message ?? null); |
| 412 | return; |
| 413 | } |
| 414 | const nextWorkspace = workspaceKey(next); |
| 415 | activateWorkspace(nextWorkspace); |
| 416 | if (previousWorkspace.current !== null && previousWorkspace.current !== nextWorkspace) { |
| 417 | everConnected.current = false; |
| 418 | workspaceMounted.current = false; |
| 419 | preferencesApplied.current = false; |
| 420 | } |
| 421 | previousWorkspace.current = nextWorkspace; |
| 422 | if (next.kind === "ssh") { |
| 423 | if (!preferencesApplied.current) { |
| 424 | preferencesApplied.current = true; |
| 425 | applyRemotePreferences(next); |
| 426 | } |
| 427 | if (next.session.status === "connected") { |
| 428 | everConnected.current = true; |
| 429 | workspaceMounted.current = true; |
| 430 | setRetriedInteractiveError(null); |
| 431 | } else if (next.session.status === "disconnected" && next.session.error === null) { |
| 432 | workspaceMounted.current = false; |
| 433 | } |
| 434 | } |
| 435 | setRuntime(next); |
| 436 | setError(runtimeQuery.error?.message ?? null); |
| 437 | }, [launchPlaceholder, runtimeQuery.data, runtimeQuery.error]); |
| 438 | |
| 439 | useEffect(() => { |
| 440 | const remote = runtime?.kind === "ssh"; |
| 441 | setFavicon(remote); |
| 442 | if (remote && (!everConnected.current || (runtime.session.status === "disconnected" && !runtime.session.error))) { |
| 443 | document.title = "OpenResearch"; |
nothing calls this directly
no test coverage detected