diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsx
index 9e88f9379e..48462b937a 100644
--- a/apps/web/src/routes/_chat.index.tsx
+++ b/apps/web/src/routes/_chat.index.tsx
@@ -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 ;
+ if (!bootstrapped || mostRecentProject !== null) {
+ return null;
}
- return ;
+ return ;
}
function NoProjectsHero() {
diff --git a/apps/web/src/state/entities.ts b/apps/web/src/state/entities.ts
index b4fc8cc5e8..db895e37c4 100644
--- a/apps/web/src/state/entities.ts
+++ b/apps/web/src/state/entities.ts
@@ -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 = Object.freeze([]);
@@ -113,6 +114,10 @@ export function useThreadShells(): ReadonlyArray {
return useAtomValue(environmentThreadShells.threadShellsAtom);
}
+export function useAllEnvironmentShellsBootstrapped(): boolean {
+ return useAtomValue(allEnvironmentShellsBootstrappedAtom);
+}
+
export function useThreadShellsForProjectRefs(
refs: ReadonlyArray,
): ReadonlyArray {
diff --git a/apps/web/src/state/shell.ts b/apps/web/src/state/shell.ts
index e879dd25e2..b9756aaf81 100644
--- a/apps/web/src/state/shell.ts
+++ b/apps/web/src/state/shell.ts
@@ -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"));