Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Preserve draft thread highlighting during promotion (#4283)

Julius Marminge18fa89c4adaa
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index cf3fa30cf..a765fe64d 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -118,7 +118,7 @@ import { vcsEnvironment } from "../state/vcs";
import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
import {
buildThreadRouteParams,
- resolveThreadRouteRef,
+ resolveActiveThreadRouteRef,
resolveThreadRouteTarget,
} from "../threadRoutes";
import { stackedThreadToast, toastManager } from "./ui/toast";
@@ -3068,10 +3068,17 @@ export default function Sidebar() {
const handleNewThread = useNewThreadHandler();
const { archiveThread, deleteThread } = useThreadActions();
const { isMobile, setOpenMobile } = useSidebar();
- const routeThreadRef = useParams({
+ const routeTarget = useParams({
strict: false,
- select: (params) => resolveThreadRouteRef(params),
+ select: (params) => resolveThreadRouteTarget(params),
});
+ const routeDraftThread = useComposerDraftStore((store) =>
+ routeTarget?.kind === "draft" ? store.getDraftSession(routeTarget.draftId) : null,
+ );
+ const routeThreadRef = useMemo(
+ () => resolveActiveThreadRouteRef(routeTarget, routeDraftThread),
+ [routeDraftThread, routeTarget],
+ );
const routeThreadKey = routeThreadRef ? scopedThreadKey(routeThreadRef) : null;
const routeTerminalOpen = useTerminalUiStateStore((state) =>
routeThreadRef
diff --git a/apps/web/src/threadRoutes.test.ts b/apps/web/src/threadRoutes.test.ts
index d15a233a3..644cdccb5 100644
--- a/apps/web/src/threadRoutes.test.ts
+++ b/apps/web/src/threadRoutes.test.ts
@@ -6,6 +6,7 @@ import { DraftId } from "./composerDraftStore";
import {
buildDraftThreadRouteParams,
buildThreadRouteParams,
+ resolveActiveThreadRouteRef,
resolveThreadRouteRef,
resolveThreadRouteTarget,
} from "./threadRoutes";
@@ -64,4 +65,31 @@ describe("threadRoutes", () => {
draftId: "draft-1",
});
});
+
+ it("resolves the backing thread while a draft route is being promoted", () => {
+ const target = resolveThreadRouteTarget({ draftId: "draft-1" });
+
+ expect(
+ resolveActiveThreadRouteRef(target, {
+ environmentId: "env-1" as never,
+ threadId: ThreadId.make("draft-thread"),
+ promotedTo: scopeThreadRef("env-2" as never, ThreadId.make("server-thread")),
+ }),
+ ).toEqual({
+ environmentId: "env-2",
+ threadId: "server-thread",
+ });
+ });
+
+ it("does not treat a draft's reserved thread ref as an active sidebar thread", () => {
+ const target = resolveThreadRouteTarget({ draftId: "draft-1" });
+
+ expect(
+ resolveActiveThreadRouteRef(target, {
+ environmentId: "env-1" as never,
+ threadId: ThreadId.make("draft-thread"),
+ promotedTo: null,
+ }),
+ ).toBeNull();
+ });
});
diff --git a/apps/web/src/threadRoutes.ts b/apps/web/src/threadRoutes.ts
index 19a7d5ca6..a4d853c0a 100644
--- a/apps/web/src/threadRoutes.ts
+++ b/apps/web/src/threadRoutes.ts
@@ -12,6 +12,12 @@ export type ThreadRouteTarget =
draftId: DraftId;
};
+type DraftThreadRouteState = {
+ environmentId: EnvironmentId;
+ threadId: ThreadId;
+ promotedTo?: ScopedThreadRef | null;
+};
+
export function buildThreadRouteParams(ref: ScopedThreadRef): {
environmentId: EnvironmentId;
threadId: ThreadId;
@@ -57,3 +63,20 @@ export function resolveThreadRouteTarget(
draftId: params.draftId as DraftId,
};
}
+
+/**
+ * Resolves the thread represented by either a canonical thread route or a
+ * draft route whose promotion to a server thread has been recorded.
+ */
+export function resolveActiveThreadRouteRef(
+ target: ThreadRouteTarget | null,
+ draftThread: DraftThreadRouteState | null,
+): ScopedThreadRef | null {
+ if (target?.kind === "server") {
+ return target.threadRef;
+ }
+ if (target?.kind !== "draft" || !draftThread?.promotedTo) {
+ return null;
+ }
+ return draftThread.promotedTo;
+}