Preserve draft thread highlighting during promotion (#4283)

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex authored and GitHub committed 2026-07-22 17:26:41 +02:00
1 parent f74eb62661
commit 18fa89c4ad
3 files changed
+61 -3

No files matched your search

+10 -3
View File
@@ -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
+28
View File
@@ -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();
});
});
+23
View File
@@ -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;
}