@devries-cameron20 / t3code-1 / commits / 56f41466f5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): sending a new thread's first message no longer scrolls the sidebar (#37557)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Mohit Dayma committed Nov 16, 2026 at 13:55 UTC 56f41466f5512e8a60e365305cd0ac9aef51ec49
5 files changed +79 -6
apps/web/src/components/Sidebar.logic.test.ts
+4
@@ -1509,6 +1509,7 @@ describe("resolveSidebarRouteReveal", () => {
1509 resolveSidebarRouteReveal({
1510 reveal: { observedKey: "environment-test:other", pendingKey: null },
1511 routeKey: hiddenKey,
1512 + routeKeyInPlace: false,
1513 isSearching: false,
1514 scopedProjectKeys,
1515 delegatedUnderParent: new Set(),
@@ -1523,6 +1524,7 @@ describe("resolveSidebarRouteReveal", () => {
1524 resolveSidebarRouteReveal({
1525 reveal: { observedKey: hiddenKey, pendingKey: null },
1526 routeKey: hiddenKey,
1527 + routeKeyInPlace: false,
1528 isSearching: false,
1529 scopedProjectKeys,
1530 delegatedUnderParent: new Set(),
@@ -1539,6 +1541,7 @@ describe("resolveSidebarRouteReveal", () => {
1541 resolveSidebarRouteReveal({
1542 reveal,
1543 routeKey,
1544 + routeKeyInPlace: false,
1545 isSearching: false,
1546 scopedProjectKeys,
1547 delegatedUnderParent: new Set(),
@@ -1553,6 +1556,7 @@ describe("resolveSidebarRouteReveal", () => {
1556 resolveSidebarRouteReveal({
1557 reveal: { observedKey: hiddenKey, pendingKey: hiddenKey },
1558 routeKey: hiddenKey,
1559 + routeKeyInPlace: false,
1560 isSearching: true,
1561 scopedProjectKeys,
1562 delegatedUnderParent: new Set(),
apps/web/src/components/Sidebar.tsx
+5 -1
@@ -1112,6 +1112,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1112 ? null
1113 : scopedThreadKey(resolveListedAncestorThreadRef(routeThreadRef, threads));
1114 const isSearchingThreads = threadSearchQuery.trim().length > 0;
1115 + // The open draft's first send names its thread in place; a finalized draft reached by
1116 + // navigation resolves through its redirect instead, and still reveals.
1117 + const routeKeyInPlace = routeDraftThread?.promotedTo != null;
1118
1119 // History, the palette and links can open a thread the scope hides or the list
1120 // scrolled away; a remount starts at the top, so each mount scrolls to the open
@@ -1120,6 +1123,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1123 const { widensScope: revealWidensScope } = resolveSidebarRouteReveal({
1124 reveal: routeReveal,
1125 routeKey: routeRowThreadKey,
1126 + routeKeyInPlace,
1127 isSearching: isSearchingThreads,
1128 scopedProjectKeys: chosenScopeProjectKeys,
1129 delegatedUnderParent,
@@ -1143,7 +1147,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
1147 clearSelection();
1148 setPersistedProjectScopeKeys([]);
1149 }, [clearSelection, revealWidensScope, setPersistedProjectScopeKeys]);
1146 - const revealActiveRow = useActiveRowReveal(routeReveal, routeRowThreadKey);
1150 + const revealActiveRow = useActiveRowReveal(routeReveal, routeRowThreadKey, routeKeyInPlace);
1151 const showProjectEnvironments = projectGroupsSpanEnvironments(projectGroups);
1152 const scratchMachineLabelFor = (
1153 thread: Pick<SidebarThreadSummary, "environmentId" | "projectId">,
apps/web/src/components/sidebar/routeReveal.browser.test.tsx
+20 -1
@@ -11,8 +11,9 @@ function RevealList(props: {
11 readonly reveal: SidebarRouteReveal;
12 readonly rowKeys: ReadonlyArray<string>;
13 readonly activeKey: string | null;
14 + readonly inPlace?: boolean;
15 }) {
15 - const revealActiveRow = useActiveRowReveal(props.reveal, props.activeKey);
16 + const revealActiveRow = useActiveRowReveal(props.reveal, props.activeKey, props.inPlace);
17 return (
18 <ul aria-label="Threads" style={{ height: ROW_HEIGHT_PX * 4, overflowY: "auto", margin: 0 }}>
19 {props.rowKeys.map((key) => (
@@ -73,6 +74,24 @@ describe("useActiveRowReveal", () => {
74 expect(scrollIntoView).not.toHaveBeenCalled();
75 });
76
77 + it("leaves the list where it is when the open draft's first send lists its thread", async () => {
78 + const reveal = newReveal();
79 + await using screen = await render(
80 + <RevealList reveal={reveal} rowKeys={rowKeys(40)} activeKey="thread-0" />,
81 + // No router: the route arrives as the activeKey prop.
82 + { router: false },
83 + );
84 + // A new draft names no thread until it is sent.
85 + await screen.rerender(<RevealList reveal={reveal} rowKeys={rowKeys(40)} activeKey={null} />);
86 +
87 + await screen.rerender(
88 + <RevealList reveal={reveal} rowKeys={rowKeys(50)} activeKey="thread-45" inPlace />,
89 + );
90 +
91 + await vi.waitFor(() => expect(reveal.pendingKey).toBeNull());
92 + await expect.element(screen.getByText("thread-45", { exact: true })).not.toBeInViewport();
93 + });
94 +
95 it("reveals a focused row scrolled out of view when the keyboard opens its thread", async () => {
96 const reveal = newReveal();
97 const keys = rowKeys(50);
apps/web/src/components/sidebar/routeReveal.ts
+14 -4
@@ -11,16 +11,20 @@ import { filterSidebarV2VisibleThreads } from "../Sidebar.logic";
11 export interface SidebarRouteReveal {
12 observedKey: string | null;
13 pendingKey: string | null;
14 + // A draft's first send names its thread without navigating; the user is not looking for it.
15 + pendingInPlace?: boolean;
16 }
17
18 export function pendingSidebarRouteReveal(
19 reveal: SidebarRouteReveal,
20 routeKey: string | null,
21 + inPlace = false,
22 ): string | null {
23 if (routeKey === null) return null;
24 if (reveal.observedKey !== routeKey) {
25 reveal.observedKey = routeKey;
26 reveal.pendingKey = routeKey;
27 + reveal.pendingInPlace = inPlace;
28 }
29 return reveal.pendingKey;
30 }
@@ -32,9 +36,13 @@ export function completeSidebarRouteReveal(reveal: SidebarRouteReveal): void {
36 // Each route change and each mount scroll to the open thread once. Render records
37 // the route, so a thread left before its row mounted still counts as a change.
38 // The row can mount after the route, once its shells arrive, so its ref scrolls.
35 -export function useActiveRowReveal(reveal: SidebarRouteReveal, routeKey: string | null) {
39 +export function useActiveRowReveal(
40 + reveal: SidebarRouteReveal,
41 + routeKey: string | null,
42 + inPlace = false,
43 +) {
44 const mountRevealOwed = useRef(true);
37 - pendingSidebarRouteReveal(reveal, routeKey);
45 + pendingSidebarRouteReveal(reveal, routeKey, inPlace);
46 // Returns a ref cleanup while it waits on a hidden row, so an unmount releases the wait.
47 const revealRow = (row: HTMLElement | null, rowKey: string): (() => void) | undefined => {
48 if (row === null) return undefined;
@@ -49,11 +57,12 @@ export function useActiveRowReveal(reveal: SidebarRouteReveal, routeKey: string
57 });
58 return stopWaiting;
59 }
60 + const revealInPlace = reveal.pendingKey === rowKey && reveal.pendingInPlace === true;
61 completeSidebarRouteReveal(reveal);
62 mountRevealOwed.current = false;
63 // A row under the pointer was just clicked, so it is in view; scrolling it would force a
64 // layout mid-commit. Keyboard activation can come from a focused row scrolled out of view.
56 - if (row.matches(":hover")) return undefined;
65 + if (revealInPlace || row.matches(":hover")) return undefined;
66 row.scrollIntoView({ block: "nearest" });
67 return undefined;
68 };
@@ -68,6 +77,7 @@ type RevealableThread = Parameters<typeof filterSidebarV2VisibleThreads>[0][numb
77 export function resolveSidebarRouteReveal<T extends RevealableThread>(input: {
78 readonly reveal: SidebarRouteReveal;
79 readonly routeKey: string | null;
80 + readonly routeKeyInPlace: boolean;
81 readonly isSearching: boolean;
82 readonly scopedProjectKeys: ReadonlySet<string> | null;
83 readonly delegatedUnderParent: ReadonlySet<string>;
@@ -75,7 +85,7 @@ export function resolveSidebarRouteReveal<T extends RevealableThread>(input: {
85 }): { readonly pendingKey: string | null; readonly widensScope: boolean } {
86 const { reveal, routeKey, isSearching, scopedProjectKeys, delegatedUnderParent, findThread } =
87 input;
78 - const pendingKey = pendingSidebarRouteReveal(reveal, routeKey);
88 + const pendingKey = pendingSidebarRouteReveal(reveal, routeKey, input.routeKeyInPlace);
89 // Search results replace the thread list; the reveal waits for it to return.
90 const thread = pendingKey === null || isSearching ? undefined : findThread(pendingKey);
91 const widensScope =
scripts/scenarios/first-send-keeps-sidebar-scroll.e2e.ts new
+36
@@ -0,0 +1,36 @@
1 +import { expect } from "e2e";
2 +
3 +import { test, WEB } from "./t3.ts";
4 +
5 +test(
6 + "Sending a new thread's first message leaves the sidebar where it was",
7 + WEB,
8 + async ({ t3, app, browser, screen }) => {
9 + const project = await t3.project("demo");
10 + for (let index = 1; index <= 12; index += 1) {
11 + await t3.thread({ project, title: `Earlier work ${index}`, messages: ["first"] });
12 + }
13 + // Short enough that the Working shelf, below the listed threads, starts out of view.
14 + await browser.setViewport({ width: 1280, height: 520 });
15 + await t3.open();
16 + await expect(screen.getByRole("button", "Earlier work 12", { exact: false })).toBeVisible();
17 + const sidebarScrollTop = () =>
18 + browser.evaluate(
19 + () =>
20 + document.querySelector("[data-sidebar-row]")?.closest("[data-slot=scroll-area-viewport]")
21 + ?.scrollTop ?? -1,
22 + );
23 + expect(await sidebarScrollTop()).toBe(0);
24 +
25 + await screen.getByRole("textbox").fill("Give me a short tour");
26 + await screen.getByRole("textbox").press("Enter");
27 + await expect(screen.getByRole("button", "Stop generation")).toBeVisible();
28 + // The new thread's row mounts in the Working shelf, below the fold.
29 + await expect(
30 + screen.getByRole("button", "Give me a short tour, Working", { exact: false }),
31 + ).toBeAttached();
32 + await app.screenshot("after-first-send");
33 +
34 + expect(await sidebarScrollTop()).toBe(0);
35 + },
36 +);