The best way to control Claude Code, Codex and more from any computer or phone
fix(web): thread shortcuts work with the narrow sidebar closed (#23568)
Julius Marminge committed
Nov 11, 2026 at 16:59 UTC
338e73859abdaa0d88a39cdb06a56fe512c6a1d4
6 files changed
+132
-16
apps/web/src/components/Sidebar.motion.ts
+6
@@ -120,6 +120,12 @@ export function createSidebarListMotion(parent: HTMLUListElement) {
120
return {
121
update(animate: boolean) {
122
if (disposed) return;
123
+ // A hidden list (the closed narrow sheet stays mounted) reports zero
124
+ // offsets, which would make the first pass after it opens animate every row.
125
+ if (parent.getClientRects().length === 0) {
126
+ suspend();
127
+ return;
128
+ }
129
const next = new Map(
130
Array.from(parent.children)
131
.filter((node): node is HTMLElement => node instanceof HTMLElement && !exiting.has(node))
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+8
-3
@@ -560,7 +560,7 @@ type SidebarThreadRowProps = {
560
wokeAt: string | null;
561
isActive: boolean;
562
// Set on the active row only; scrolls it into view when a reveal is owed.
563
- revealRef?: ((row: HTMLElement, threadKey: string) => void) | undefined;
563
+ revealRef?: ((row: HTMLElement, threadKey: string) => (() => void) | undefined) | undefined;
564
// Unlike isActive, never true for the ancestor standing in for an open
565
// subagent: drafts and PR clicks care about which composer is on screen.
566
isRouteThread: boolean;
@@ -668,8 +668,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
668
const { leaseLiveStatus, rowRef: leaseRowRef } = useSidebarRowSubscriptionLease(props.isActive);
669
const { revealRef } = props;
670
const rowRef = (row: HTMLElement | null) => {
671
- if (row !== null) revealRef?.(row, threadKey);
672
- return leaseRowRef(row);
671
+ const stopReveal = row === null ? undefined : revealRef?.(row, threadKey);
672
+ const releaseLease = leaseRowRef(row);
673
+ if (!stopReveal) return releaseLease;
674
+ return () => {
675
+ stopReveal();
676
+ releaseLease?.();
677
+ };
678
};
679
const isRegeneratingTitle = thread.titleRegeneration != null;
680
const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]);
apps/web/src/components/sidebar/routeReveal.browser.test.tsx
+50
-1
@@ -1,7 +1,8 @@
1
import { describe, expect, it, vi } from "vite-plus/test";
2
-import { userEvent } from "vite-plus/test/browser";
2
+import { page, userEvent } from "vite-plus/test/browser";
3
4
import { render } from "../../../test/render";
5
+import { Sidebar, SidebarProvider, SidebarTrigger, useSidebar } from "../ui/sidebar";
6
import { type SidebarRouteReveal, useActiveRowReveal } from "./routeReveal";
7
8
const ROW_HEIGHT_PX = 24;
@@ -28,6 +29,12 @@ function RevealList(props: {
29
);
30
}
31
32
+// Reads the sidebar context like the real thread list, so opening the sheet re-renders it.
33
+function SheetRevealList(props: Parameters<typeof RevealList>[0]) {
34
+ useSidebar();
35
+ return <RevealList {...props} />;
36
+}
37
+
38
const rowKeys = (count: number) => Array.from({ length: count }, (_, index) => `thread-${index}`);
39
const newReveal = (): SidebarRouteReveal => ({ observedKey: null, pendingKey: null });
40
@@ -141,4 +148,46 @@ describe("useActiveRowReveal", () => {
148
);
149
await expect.element(screen.getByText("thread-40", { exact: true })).toBeInViewport();
150
});
151
+
152
+ it("stops watching a hidden active row once it unmounts", async () => {
153
+ const reveal = newReveal();
154
+ using observe = vi.spyOn(ResizeObserver.prototype, "observe");
155
+ using unobserve = vi.spyOn(ResizeObserver.prototype, "unobserve");
156
+ using disconnect = vi.spyOn(ResizeObserver.prototype, "disconnect");
157
+ await using screen = await render(
158
+ <div hidden>
159
+ <RevealList reveal={reveal} rowKeys={rowKeys(50)} activeKey="thread-40" />
160
+ </div>,
161
+ // No router: the route arrives as the activeKey prop.
162
+ { router: false },
163
+ );
164
+ const row = screen.getByText("thread-40", { exact: true }).element();
165
+ expect(observe).toHaveBeenCalledWith(row);
166
+
167
+ // A widening viewport unmounts the closed sheet before it ever opens.
168
+ await screen.rerender(<div hidden />);
169
+
170
+ expect(
171
+ unobserve.mock.calls.some(([target]) => target === row) || disconnect.mock.calls.length > 0,
172
+ ).toBe(true);
173
+ });
174
+
175
+ it("reveals the open thread when the closed narrow sheet opens", async () => {
176
+ await page.viewport(390, 844);
177
+ const reveal = newReveal();
178
+ await using screen = await render(
179
+ <SidebarProvider>
180
+ <Sidebar>
181
+ <SheetRevealList reveal={reveal} rowKeys={rowKeys(50)} activeKey="thread-40" />
182
+ </Sidebar>
183
+ <SidebarTrigger />
184
+ </SidebarProvider>,
185
+ // No router: the route arrives as the activeKey prop.
186
+ { router: false },
187
+ );
188
+
189
+ await userEvent.click(screen.getByRole("button", { name: "Toggle Sidebar" }));
190
+
191
+ await expect.element(page.getByText("thread-40", { exact: true })).toBeInViewport();
192
+ });
193
});
apps/web/src/components/sidebar/routeReveal.ts
+19
-4
@@ -1,5 +1,7 @@
1
import { useRef } from "react";
2
3
+import { observeResize } from "~/lib/observeResize";
4
+
5
import { filterSidebarV2VisibleThreads } from "../Sidebar.logic";
6
7
// AppSidebarLayout owns this so drawer and Settings remounts preserve the chosen project scope.
@@ -33,16 +35,29 @@ export function completeSidebarRouteReveal(reveal: SidebarRouteReveal): void {
35
export function useActiveRowReveal(reveal: SidebarRouteReveal, routeKey: string | null) {
36
const mountRevealOwed = useRef(true);
37
pendingSidebarRouteReveal(reveal, routeKey);
36
- return (row: HTMLElement | null, rowKey: string) => {
37
- if (row === null) return;
38
- if (reveal.pendingKey !== rowKey && !mountRevealOwed.current) return;
38
+ // Returns a ref cleanup while it waits on a hidden row, so an unmount releases the wait.
39
+ const revealRow = (row: HTMLElement | null, rowKey: string): (() => void) | undefined => {
40
+ if (row === null) return undefined;
41
+ if (reveal.pendingKey !== rowKey && !mountRevealOwed.current) return undefined;
42
+ // The closed narrow sheet keeps rows mounted but hidden, and opening it does not
43
+ // re-render them, so wait for the row to get a box before spending the reveal.
44
+ if (row.getClientRects().length === 0) {
45
+ const stopWaiting = observeResize(row, () => {
46
+ if (row.getClientRects().length === 0) return;
47
+ stopWaiting();
48
+ revealRow(row, rowKey);
49
+ });
50
+ return stopWaiting;
51
+ }
52
completeSidebarRouteReveal(reveal);
53
mountRevealOwed.current = false;
54
// A row under the pointer was just clicked, so it is in view; scrolling it would force a
55
// layout mid-commit. Keyboard activation can come from a focused row scrolled out of view.
43
- if (row.matches(":hover")) return;
56
+ if (row.matches(":hover")) return undefined;
57
row.scrollIntoView({ block: "nearest" });
58
+ return undefined;
59
};
60
+ return revealRow;
61
}
62
63
type RevealableThread = Parameters<typeof filterSidebarV2VisibleThreads>[0][number];
apps/web/src/components/ui/sidebar.browser.test.tsx
+30
@@ -130,3 +130,33 @@ it("keeps the mobile sheet closed and leaves the saved desktop state alone", asy
130
.toHaveAttribute("aria-pressed", "false");
131
localStorage.removeItem(storageKey);
132
});
133
+
134
+function MobileSheetMountedProbe() {
135
+ const { mobileSheetMounted } = useSidebar();
136
+ return <output aria-label="Sheet mounted">{String(mobileSheetMounted)}</output>;
137
+}
138
+
139
+it("keeps closed mobile sheet contents mounted and reports the sheet only while it shows", async () => {
140
+ await page.viewport(390, 844);
141
+ await using screen = await render(
142
+ <SidebarProvider>
143
+ <Sidebar>
144
+ <span>Sheet contents</span>
145
+ </Sidebar>
146
+ <SidebarTrigger />
147
+ <MobileSheetMountedProbe />
148
+ </SidebarProvider>,
149
+ { router: false /* no routes involved */ },
150
+ );
151
+ const sheetMounted = screen.getByLabelText("Sheet mounted");
152
+ // Window shortcuts registered by sidebar children only work while they stay mounted.
153
+ expect(document.querySelector('[data-mobile="true"]')?.textContent).toContain("Sheet contents");
154
+ await expect.element(sheetMounted).toHaveTextContent("false");
155
+
156
+ await userEvent.click(screen.getByRole("button", { name: "Toggle Sidebar" }));
157
+ await expect.element(sheetMounted).toHaveTextContent("true");
158
+
159
+ await userEvent.keyboard("{Escape}");
160
+ await expect.element(sheetMounted).toHaveTextContent("false");
161
+ expect(document.querySelector('[data-mobile="true"]')?.textContent).toContain("Sheet contents");
162
+});
apps/web/src/components/ui/sidebar.tsx
+19
-8
@@ -38,7 +38,7 @@ type SidebarContextProps = {
38
setOpen: (open: boolean) => void;
39
openMobile: boolean;
40
mobileSheetMounted: boolean;
41
- setMobileSheetElement: (element: HTMLDivElement | null) => void;
41
+ setMobileSheetMounted: (mounted: boolean) => void;
42
setOpenMobile: (open: boolean) => void;
43
isMobile: boolean;
44
toggleSidebar: () => void;
@@ -204,9 +204,13 @@ function SidebarProvider({
204
store.getSnapshot,
205
);
206
const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false);
207
- const setMobileSheetElement = (element: HTMLDivElement | null) => {
208
- setMobileSheetMounted(element !== null);
209
- };
207
+ if (openMobile && !mobileSheetMounted) {
208
+ setMobileSheetMounted(true);
209
+ }
210
+ // Widening mid-close unmounts the sheet before its close completes.
211
+ if (!isMobile && !openMobile && mobileSheetMounted) {
212
+ setMobileSheetMounted(false);
213
+ }
214
215
const state = resolveSidebarState({ isMobile, open, openMobile });
216
@@ -215,7 +219,7 @@ function SidebarProvider({
219
open,
220
openMobile,
221
mobileSheetMounted,
218
- setMobileSheetElement,
222
+ setMobileSheetMounted,
223
setOpen: store.setOpen,
224
setOpenMobile: store.setOpenMobile,
225
state,
@@ -287,7 +291,7 @@ function Sidebar({
291
collapsible?: "offcanvas" | "icon" | "none";
292
resizable?: boolean | SidebarResizableOptions;
293
}) {
290
- const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar();
294
+ const { isMobile, state, openMobile, setOpenMobile, setMobileSheetMounted } = useSidebar();
295
const offcanvasCollapsed = !isMobile && collapsible === "offcanvas" && state === "collapsed";
296
297
const resolvedResizable = resolveSidebarResizable({ collapsible, isMobile, resizable });
@@ -313,9 +317,16 @@ function Sidebar({
317
if (isMobile) {
318
return (
319
<SidebarInstanceContext value={instanceContextValue}>
316
- <Sheet onOpenChange={setOpenMobile} open={openMobile}>
320
+ <Sheet
321
+ onOpenChange={setOpenMobile}
322
+ onOpenChangeComplete={(open) => {
323
+ if (!open) setMobileSheetMounted(false);
324
+ }}
325
+ open={openMobile}
326
+ >
327
+ {/* Children stay mounted while closed so their window shortcuts, like thread jumps, keep working. */}
328
<SheetPopup
318
- ref={setMobileSheetElement}
329
+ keepMounted
330
className={cn(
331
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
332
className,