The best way to control Claude Code, Codex and more from any computer or phone
fix(web): the new-thread project picker follows the manual project order (#29846)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Southwell committed
Nov 15, 2026 at 02:18 UTC
f751c8488f7ca1e659e44ef12b05861c1bcf9bfb
3 files changed
+109
-16
apps/web/src/components/chat/DraftHeroHeadline.browser.test.tsx
new
+94
@@ -0,0 +1,94 @@
1
+import { createMemoryHistory } from "@tanstack/react-router";
2
+import { scopeProjectRef } from "@t3tools/client-runtime/environment";
3
+import { ProjectId } from "@t3tools/contracts";
4
+import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
5
+import type * as Context from "effect/Context";
6
+import { expect, it, vi } from "vite-plus/test";
7
+import { page, userEvent } from "vite-plus/test/browser";
8
+
9
+import { AppRoot } from "~/AppRoot";
10
+// The draft route loads ChatView lazily; importing it here keeps its first transform out of the test's timeout.
11
+import "~/components/ChatView";
12
+import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
13
+import { __setClientSettingsForTests } from "~/hooks/useSettings";
14
+import { getRouter } from "~/router";
15
+import { useUiStateStore } from "~/uiStateStore";
16
+import {
17
+ ENVIRONMENT_ID,
18
+ PROJECT_ID,
19
+ installFakeEnvironment,
20
+ type FakeDriver,
21
+} from "../../../test/fakeEnvironment";
22
+import { render } from "../../../test/render";
23
+
24
+// The socket is the only fake layer; see test/appScenarios.renders.tsx.
25
+vi.mock(
26
+ "../../../../../packages/client-runtime/src/connection/driver.ts",
27
+ async (importOriginal) => {
28
+ const [actual, { fakeDriver }, Layer] = await Promise.all([
29
+ importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(),
30
+ import("../../../test/fakeEnvironment"),
31
+ import("effect/Layer"),
32
+ ]);
33
+ return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
34
+ },
35
+);
36
+
37
+vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
38
+ ...(await original()),
39
+ trackRpcRequestSent: () => {},
40
+}));
41
+
42
+it("the new-thread project picker follows the manual sidebar project order", async () => {
43
+ using _environment = installFakeEnvironment([], {
44
+ extraProjects: [
45
+ { id: ProjectId.make("project-alpha"), title: "alpha" },
46
+ { id: ProjectId.make("project-beta"), title: "beta" },
47
+ ],
48
+ });
49
+ __setClientSettingsForTests({
50
+ ...DEFAULT_CLIENT_SETTINGS,
51
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
52
+ sidebarProjectSortOrder: "manual",
53
+ });
54
+ useUiStateStore.setState({
55
+ projectOrder: [
56
+ `${ENVIRONMENT_ID}:/workspace/beta`,
57
+ `${ENVIRONMENT_ID}:/workspace/render`,
58
+ `${ENVIRONMENT_ID}:/workspace/alpha`,
59
+ ],
60
+ });
61
+ using _order = { [Symbol.dispose]: () => useUiStateStore.setState({ projectOrder: [] }) };
62
+ const draftId = DraftId.make("draft-manual-order");
63
+ useComposerDraftStore
64
+ .getState()
65
+ .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId);
66
+
67
+ const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
68
+ await router.load();
69
+ await using _app = await render(<AppRoot router={router} />, {
70
+ // AppRoot brings its own router.
71
+ router: false,
72
+ });
73
+ // The shell snapshot has arrived once the sidebar lists the project.
74
+ await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
75
+ const trigger = document.querySelector<HTMLElement>("[data-draft-project-trigger]");
76
+ if (!trigger) throw new Error("The draft project picker did not render.");
77
+ await userEvent.click(page.elementLocator(trigger));
78
+ await expect.element(page.getByRole("option", { name: "beta" })).toBeVisible();
79
+
80
+ // The draft's own project leads; the rest keep the sidebar's order.
81
+ await vi.waitFor(() => {
82
+ expect(
83
+ page
84
+ .getByRole("option")
85
+ .elements()
86
+ .map((option) => option.textContent),
87
+ ).toEqual([
88
+ expect.stringMatching(/render$/),
89
+ expect.stringMatching(/beta$/),
90
+ expect.stringMatching(/alpha$/),
91
+ "Add project",
92
+ ]);
93
+ });
94
+});
apps/web/src/components/chat/DraftHeroHeadline.tsx
+3
-15
@@ -24,10 +24,9 @@ import {
24
} from "@t3tools/client-runtime/state/project-grouping";
25
import {
26
buildSidebarProjectPickerEntries,
27
- buildSidebarProjectSnapshots,
27
projectGroupsSpanEnvironments,
28
} from "~/sidebarProjectGrouping";
30
-import { useProjects, useVisibleThreadShells } from "~/state/entities";
29
+import { useProjects } from "~/state/entities";
30
import {
31
useEnvironments,
32
usePrimaryEnvironmentId,
@@ -36,7 +35,7 @@ import {
35
import { ProjectEnvironmentBadge } from "../ProjectEnvironmentBadge";
36
import { ProjectFavicon } from "../ProjectFavicon";
37
import { isProjectPinShortcut, ProjectPinButton } from "../ProjectPinButton";
39
-import { sortLogicalProjectsForSidebar } from "../Sidebar.logic";
38
+import { useSortedProjectGroups } from "../CommandPaletteLookups";
39
import {
40
Combobox,
41
ComboboxEmpty,
@@ -75,12 +74,10 @@ export function DraftHeroHeadline({
74
activeProjectTitle,
75
}: DraftHeroHeadlineProps) {
76
const projects = useProjects();
78
- const threads = useVisibleThreadShells();
77
const { environments } = useEnvironments();
78
const providersByEnvironment = useEnvironmentProviders();
79
const primaryEnvironmentId = usePrimaryEnvironmentId();
80
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
83
- const projectSortOrder = useClientSettings((settings) => settings.sidebarProjectSortOrder);
81
const setLogicalProjectDraftThreadId = useComposerDraftStore(
82
(store) => store.setLogicalProjectDraftThreadId,
83
);
@@ -104,16 +101,7 @@ export function DraftHeroHeadline({
101
const environmentLabelById = new Map(
102
environments.map((environment) => [environment.environmentId, environment.label] as const),
103
);
107
- const projectGroups = sortLogicalProjectsForSidebar(
108
- buildSidebarProjectSnapshots({
109
- projects,
110
- settings: projectGroupingSettings,
111
- primaryEnvironmentId,
112
- resolveEnvironmentLabel: (environmentId) => environmentLabelById.get(environmentId) ?? null,
113
- }),
114
- threads,
115
- projectSortOrder,
116
- );
104
+ const projectGroups = useSortedProjectGroups(environmentLabelById);
105
const showProjectEnvironments = projectGroupsSpanEnvironments(projectGroups);
106
const environmentMachineById = new Map(
107
environments.map(
apps/web/test/fakeEnvironment.ts
+12
-1
@@ -408,6 +408,7 @@ let terminalMetadataSubscriber: Queue.Queue<TerminalMetadataStreamEvent> | null
408
let threads: ReadonlyArray<FakeThread> = [];
409
let dispatched: OrchestrationV2Command[] = [];
410
let acceptCommands = false;
411
+let projects: ReadonlyArray<OrchestrationProjectShell> = [project];
412
let holdCommand: (command: OrchestrationV2Command) => boolean = () => false;
413
let pendingDispatches: Array<{
414
readonly command: OrchestrationV2Command;
@@ -463,7 +464,7 @@ const handlers: Record<string, (input: never) => unknown> = {
464
snapshot: {
465
schemaVersion: 1,
466
snapshotSequence: sequence,
466
- projects: [project],
467
+ projects,
468
threads: threads.filter((thread) => !thread.olderSettled).map(shellOf),
469
archivedThreads: [],
470
},
@@ -561,6 +562,7 @@ export function installFakeEnvironment(
562
fixtures: ReadonlyArray<FakeThread>,
563
options?: {
564
readonly acceptCommands?: boolean;
565
+ readonly extraProjects?: ReadonlyArray<Pick<OrchestrationProjectShell, "id" | "title">>;
566
/** Commands left unanswered even when accepting, until `rejectPendingCommand`. */
567
readonly holdCommand?: (command: OrchestrationV2Command) => boolean;
568
readonly providers?: ReadonlyArray<unknown>;
@@ -570,6 +572,14 @@ export function installFakeEnvironment(
572
baseServerConfig = makeServerConfig(options?.providers ?? [CODEX_PROVIDER]);
573
dispatched = [];
574
acceptCommands = options?.acceptCommands === true;
575
+ projects = [
576
+ project,
577
+ ...(options?.extraProjects ?? []).map((extra) => ({
578
+ ...project,
579
+ ...extra,
580
+ workspaceRoot: `/workspace/${extra.title}`,
581
+ })),
582
+ ];
583
holdCommand = options?.holdCommand ?? (() => false);
584
globalThis.fetch = async (input, init) => {
585
const url = new URL(input instanceof Request ? input.url : String(input), window.location.href);
@@ -595,6 +605,7 @@ export function installFakeEnvironment(
605
baseServerConfig = makeServerConfig([CODEX_PROVIDER]);
606
dispatched = [];
607
acceptCommands = false;
608
+ projects = [project];
609
holdCommand = () => false;
610
pendingDispatches = [];
611
pendingAssetUrls = [];