fix(web): make the index auto-draft wait for shell bootstrap and recover from failures

Signed-off-by: Yordis Prieto <[email protected]>
This commit is contained in:
Yordis Prieto committed 2026-07-16 13:28:49 -04:00
1 parent 7b7119e71c
commit d91b635b48
3 files changed
+33 -10

No files matched your search

+17 -10
View File
@@ -4,13 +4,16 @@ import { LinkIcon, PlusIcon } from "lucide-react";
import { useEffect, useMemo, useRef } from "react";
import { useOpenAddProjectCommandPalette } from "../commandPaletteContext";
import { NoActiveThreadState } from "../components/NoActiveThreadState";
import { sortProjectsForSidebar } from "../components/Sidebar.logic";
import { Button } from "../components/ui/button";
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../components/ui/empty";
import { SidebarInset } from "../components/ui/sidebar";
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
import { useProjects, useThreadShells } from "../state/entities";
import {
useAllEnvironmentShellsBootstrapped,
useProjects,
useThreadShells,
} from "../state/entities";
import { useEnvironments } from "../state/environments";
import { APP_DISPLAY_NAME } from "~/branding";
import { hasCloudPublicConfig } from "~/cloud/publicConfig";
@@ -36,28 +39,32 @@ function ChatIndexRouteView() {
function IndexDraftLanding() {
const projects = useProjects();
const threads = useThreadShells();
const bootstrapped = useAllEnvironmentShellsBootstrapped();
const handleNewThread = useNewThreadHandler();
const startedRef = useRef(false);
const startingRef = useRef(false);
const mostRecentProject = useMemo(
() => sortProjectsForSidebar(projects, threads, "updated_at")[0] ?? null,
[projects, threads],
() =>
bootstrapped ? (sortProjectsForSidebar(projects, threads, "updated_at")[0] ?? null) : null,
[bootstrapped, projects, threads],
);
useEffect(() => {
if (mostRecentProject === null || startedRef.current) {
if (mostRecentProject === null || startingRef.current) {
return;
}
startedRef.current = true;
startingRef.current = true;
void handleNewThread(scopeProjectRef(mostRecentProject.environmentId, mostRecentProject.id), {
replace: true,
}).catch(() => {
startingRef.current = false;
});
}, [handleNewThread, mostRecentProject]);
if (mostRecentProject === null) {
return <NoProjectsHero />;
if (!bootstrapped || mostRecentProject !== null) {
return null;
}
return <NoActiveThreadState />;
return <NoProjectsHero />;
}
function NoProjectsHero() {
+5
View File
@@ -20,6 +20,7 @@ import { useMemo } from "react";
import { appAtomRegistry } from "../rpc/atomRegistry";
import { environmentProjects } from "./projects";
import { environmentServerConfigsAtom } from "./server";
import { allEnvironmentShellsBootstrappedAtom } from "./shell";
import { environmentThreadDetails, environmentThreadShells } from "./threads";
const EMPTY_PROJECT_REFS: ReadonlyArray<ScopedProjectRef> = Object.freeze([]);
@@ -113,6 +114,10 @@ export function useThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
return useAtomValue(environmentThreadShells.threadShellsAtom);
}
export function useAllEnvironmentShellsBootstrapped(): boolean {
return useAtomValue(allEnvironmentShellsBootstrappedAtom);
}
export function useThreadShellsForProjectRefs(
refs: ReadonlyArray<ScopedProjectRef>,
): ReadonlyArray<EnvironmentThreadShell> {
+11
View File
@@ -4,6 +4,8 @@ import {
createEnvironmentSnapshotAtom,
createShellEnvironmentAtoms,
} from "@t3tools/client-runtime/state/shell";
import * as Option from "effect/Option";
import { Atom } from "effect/unstable/reactivity";
import { environmentCatalog } from "../connection/catalog";
import { connectionAtomRuntime } from "../connection/runtime";
@@ -15,3 +17,12 @@ export const environmentShellSummaryAtom = createEnvironmentShellSummaryAtom({
catalogValueAtom: environmentCatalog.catalogValueAtom,
shellStateValueAtom: environmentShell.stateValueAtom,
});
export const allEnvironmentShellsBootstrappedAtom = Atom.make((get) => {
for (const environmentId of get(environmentCatalog.catalogValueAtom).entries.keys()) {
if (Option.isNone(get(environmentShell.stateValueAtom(environmentId)).snapshot)) {
return false;
}
}
return true;
}).pipe(Atom.withLabel("web-all-environment-shells-bootstrapped"));