From 836121a508af84608467a13be46c1148590363c3 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 22 Oct 2026 09:59:05 +0000 Subject: [PATCH 1/9] fix(web): thread shortcuts work while the narrow sidebar sheet is closed Closes #21789 Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/ui/sidebar.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsx index 570e8299694fe..a1da543fb32f7 100644 --- a/apps/web/src/components/ui/sidebar.tsx +++ b/apps/web/src/components/ui/sidebar.tsx @@ -36,7 +36,7 @@ type SidebarContextProps = { setOpen: (open: boolean) => void; openMobile: boolean; mobileSheetMounted: boolean; - setMobileSheetElement: (element: HTMLDivElement | null) => void; + setMobileSheetMounted: (mounted: boolean) => void; setOpenMobile: (open: boolean) => void; isMobile: boolean; toggleSidebar: () => void; @@ -110,9 +110,9 @@ function SidebarProvider({ const isMobile = useIsMobile(); const [openMobile, setOpenMobile] = React.useState(false); const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false); - const setMobileSheetElement = (element: HTMLDivElement | null) => { - setMobileSheetMounted(element !== null); - }; + if (openMobile && !mobileSheetMounted) { + setMobileSheetMounted(true); + } const [_open, _setOpen] = React.useState(defaultOpen); const open = openProp ?? _open; @@ -143,7 +143,7 @@ function SidebarProvider({ open, openMobile, mobileSheetMounted, - setMobileSheetElement, + setMobileSheetMounted, setOpen, setOpenMobile, state, @@ -214,7 +214,7 @@ function Sidebar({ collapsible?: "offcanvas" | "icon" | "none"; resizable?: boolean | SidebarResizableOptions; }) { - const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar(); + const { isMobile, state, openMobile, setOpenMobile, setMobileSheetMounted } = useSidebar(); const desktopSidebarRef = React.useRef(null); const offcanvasCollapsed = !isMobile && collapsible === "offcanvas" && state === "collapsed"; @@ -256,9 +256,16 @@ function Sidebar({ if (isMobile) { return ( - + { + if (!open) setMobileSheetMounted(false); + }} + open={openMobile} + > + {/* Children stay mounted while closed so their window shortcuts, like thread jumps, keep working. */} Date: Thu, 22 Oct 2026 10:04:33 +0000 Subject: [PATCH 2/9] fix(web): hidden sidebar sheet no longer skews row motion or the toggle Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/Sidebar.motion.ts | 6 ++++++ apps/web/src/components/ui/sidebar.tsx | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/apps/web/src/components/Sidebar.motion.ts b/apps/web/src/components/Sidebar.motion.ts index 9362475e46a67..19851169cff30 100644 --- a/apps/web/src/components/Sidebar.motion.ts +++ b/apps/web/src/components/Sidebar.motion.ts @@ -123,6 +123,12 @@ export function createSidebarListMotion(parent: HTMLUListElement) { return { update(animate: boolean) { if (disposed) return; + // A hidden list (the closed narrow sheet stays mounted) reports zero + // offsets, which would make the first pass after it opens animate every row. + if (parent.getClientRects().length === 0) { + suspend(); + return; + } const next = new Map( Array.from(parent.children) .filter((node): node is HTMLElement => node instanceof HTMLElement && !exiting.has(node)) diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsx index a1da543fb32f7..8a61ea481fbae 100644 --- a/apps/web/src/components/ui/sidebar.tsx +++ b/apps/web/src/components/ui/sidebar.tsx @@ -113,6 +113,10 @@ function SidebarProvider({ if (openMobile && !mobileSheetMounted) { setMobileSheetMounted(true); } + // Widening mid-close unmounts the sheet before its close completes. + if (!isMobile && !openMobile && mobileSheetMounted) { + setMobileSheetMounted(false); + } const [_open, _setOpen] = React.useState(defaultOpen); const open = openProp ?? _open; From 4d3e3d92c31957981711527e22cfa78e146157d0 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 22 Oct 2026 10:40:32 +0000 Subject: [PATCH 3/9] test(web): add a synthetic sidebar evidence fixture --- scripts/seed-sidebar-evidence.py | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 scripts/seed-sidebar-evidence.py diff --git a/scripts/seed-sidebar-evidence.py b/scripts/seed-sidebar-evidence.py new file mode 100644 index 0000000000000..6f72e76f10696 --- /dev/null +++ b/scripts/seed-sidebar-evidence.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python3 +"""Seed synthetic sidebar projections in a stopped, isolated, initialized T3 home. + +Usage: python3 scripts/seed-sidebar-evidence.py --base-dir /tmp/sidebar-proof/.t3 \ + --workspace /tmp/sidebar-proof/workspace [--empty] + +Start the server once to migrate an empty isolated home, then stop it first. +Restart with T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=false so startup does not +create an unrelated project and fourth thread. +This fixture creates no event history and must not prove backend behavior. +Use identical workspace, settings, bindings and a fixed browser clock for pairs. +""" + +import argparse +import json +import os +from pathlib import Path +import sqlite3 + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--base-dir", type=Path, required=True) + parser.add_argument("--workspace", type=Path, required=True) + parser.add_argument("--empty", action="store_true") + args = parser.parse_args() + base = args.base_dir.resolve() + if base == (Path.home() / ".t3").resolve() or (base / "userdata").is_symlink(): + parser.error("Use a copied, isolated home, never the live T3 home.") + db = base / "userdata/statev2.sqlite" + if db.is_symlink(): + parser.error("The isolated database must be a copy, never a symlink.") + if not db.is_file(): + parser.error("Initialize an empty isolated home with the server first.") + runtime_file = base / "userdata/server-runtime.json" + if runtime_file.is_file(): + runtime = json.loads(runtime_file.read_text()) + try: + os.kill(runtime["pid"], 0) + except ProcessLookupError: + pass + else: + parser.error("Stop the isolated server before seeding its database.") + workspace = args.workspace.resolve(strict=True) + if not workspace.is_dir(): + parser.error("Workspace must be a directory.") + + with sqlite3.connect(db) as connection: + # Refuse existing work, including runnable effects, rather than clearing it. + for table in ( + "orchestration_v2_projection_messages", + "orchestration_v2_projection_runs", + "orchestration_v2_projection_runtime_requests", + "orchestration_v2_effect_outbox", + "scheduled_tasks", + ): + if connection.execute(f"SELECT count(*) FROM {table}").fetchone()[0]: + parser.error(f"Expected empty synthetic state: {table} is populated.") + if connection.execute( + "SELECT count(*) FROM orchestration_v2_projection_threads " + "WHERE thread_id NOT LIKE 'shortcut-fixture-%'" + ).fetchone()[0]: + parser.error("Refusing to replace nonfixture threads.") + if connection.execute( + "SELECT count(*) FROM projection_projects WHERE title != 'Shortcut fixtures'" + ).fetchone()[0]: + parser.error("Refusing to replace nonfixture projects.") + + clock = "2026-10-22T08:00:00.000Z" + project = "shortcut-fixtures" + connection.execute("DELETE FROM orchestration_v2_projection_threads") + connection.execute("DELETE FROM projection_projects") + connection.execute( + "INSERT INTO projection_projects " + "(project_id,title,workspace_root,scripts_json,created_at,updated_at) " + "VALUES (?,?,?,?,?,?)", + (project, "Shortcut fixtures", str(workspace), "[]", clock, clock), + ) + for index, title in enumerate(() if args.empty else ("Alpha", "Beta", "Gamma"), 1): + thread = f"shortcut-fixture-{index}" + payload = dict( + id=thread, projectId=project, title=f"Thread {title}", + createdBy="system", creationSource="server", + providerInstanceId="codex", + modelSelection=dict(instanceId="codex", model="gpt-6-astra"), + runtimeMode="full-access", interactionMode="default", + branch=None, worktreePath=None, pullRequests=[], + activeProviderThreadId=None, forkedFrom=None, + lineage=dict(parentThreadId=None, relationshipToParent=None, rootThreadId=thread), + createdAt=clock, updatedAt=clock, lastVisitedAt=clock, + archivedAt=None, deletedAt=None, settledOverride=None, settledAt=None, + snoozedUntil=None, snoozedAt=None, activeOrderKey=str(index), + ) + connection.execute( + "INSERT INTO orchestration_v2_projection_threads " + "(thread_id,project_id,title,default_provider,provider_instance_id," + "runtime_mode,interaction_mode,created_at,updated_at,payload_json) " + "VALUES (?,?,?,?,?,?,?,?,?,?)", + (thread, project, payload["title"], "codex", "codex", "full-access", + "default", clock, clock, json.dumps(payload)), + ) + print(f"Seeded {0 if args.empty else 3} synthetic stopped threads in {db}") + + +if __name__ == "__main__": + main() From ae5275839fffad1016343719efdf4b9e0eda47db Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 22 Oct 2026 11:44:58 +0000 Subject: [PATCH 4/9] test(web): sidebar evidence seeder refuses a hardlinked live database Co-Authored-By: Claude Opus 5.5 --- scripts/seed-sidebar-evidence.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/seed-sidebar-evidence.py b/scripts/seed-sidebar-evidence.py index 6f72e76f10696..45d2edc8d9517 100644 --- a/scripts/seed-sidebar-evidence.py +++ b/scripts/seed-sidebar-evidence.py @@ -32,6 +32,12 @@ def main(): parser.error("The isolated database must be a copy, never a symlink.") if not db.is_file(): parser.error("Initialize an empty isolated home with the server first.") + try: + is_live_db = db.samefile(Path.home() / ".t3/userdata/statev2.sqlite") + except FileNotFoundError: + is_live_db = False + if is_live_db: + parser.error("The isolated database must be a copy, never a hardlink.") runtime_file = base / "userdata/server-runtime.json" if runtime_file.is_file(): runtime = json.loads(runtime_file.read_text()) From 448a0fcf5fe89de24a4300131b7e617023da476b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 22 Oct 2026 11:55:00 +0000 Subject: [PATCH 5/9] test(web): sidebar evidence seeder replaces only its exact fixture rows Co-Authored-By: Claude Opus 5.5 --- scripts/seed-sidebar-evidence.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/seed-sidebar-evidence.py b/scripts/seed-sidebar-evidence.py index 45d2edc8d9517..cf008cf2c42b7 100644 --- a/scripts/seed-sidebar-evidence.py +++ b/scripts/seed-sidebar-evidence.py @@ -62,25 +62,30 @@ def main(): ): if connection.execute(f"SELECT count(*) FROM {table}").fetchone()[0]: parser.error(f"Expected empty synthetic state: {table} is populated.") + project, project_title = "shortcut-fixtures", "Shortcut fixtures" + # Only rows this script writes may be replaced; match them exactly. if connection.execute( - "SELECT count(*) FROM orchestration_v2_projection_threads " - "WHERE thread_id NOT LIKE 'shortcut-fixture-%'" + "SELECT count(*) FROM orchestration_v2_projection_threads WHERE NOT " + "(thread_id IN ('shortcut-fixture-1','shortcut-fixture-2','shortcut-fixture-3') " + "AND project_id IS ?)", + (project,), ).fetchone()[0]: parser.error("Refusing to replace nonfixture threads.") if connection.execute( - "SELECT count(*) FROM projection_projects WHERE title != 'Shortcut fixtures'" + "SELECT count(*) FROM projection_projects " + "WHERE NOT (project_id IS ? AND title IS ?)", + (project, project_title), ).fetchone()[0]: parser.error("Refusing to replace nonfixture projects.") clock = "2026-10-22T08:00:00.000Z" - project = "shortcut-fixtures" connection.execute("DELETE FROM orchestration_v2_projection_threads") connection.execute("DELETE FROM projection_projects") connection.execute( "INSERT INTO projection_projects " "(project_id,title,workspace_root,scripts_json,created_at,updated_at) " "VALUES (?,?,?,?,?,?)", - (project, "Shortcut fixtures", str(workspace), "[]", clock, clock), + (project, project_title, str(workspace), "[]", clock, clock), ) for index, title in enumerate(() if args.empty else ("Alpha", "Beta", "Gamma"), 1): thread = f"shortcut-fixture-{index}" From 1f7dae7370cd21ab1e7e3b0b6b2de1e69ea7ad03 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 01:26:32 +0000 Subject: [PATCH 6/9] chore(web): drop the sidebar evidence seeder from the change The seeder only produced PR evidence; it is not part of the fix. AI-assisted; verified with the tests and tools listed above. --- scripts/seed-sidebar-evidence.py | 117 ------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 scripts/seed-sidebar-evidence.py diff --git a/scripts/seed-sidebar-evidence.py b/scripts/seed-sidebar-evidence.py deleted file mode 100644 index cf008cf2c42b7..0000000000000 --- a/scripts/seed-sidebar-evidence.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env python3 -"""Seed synthetic sidebar projections in a stopped, isolated, initialized T3 home. - -Usage: python3 scripts/seed-sidebar-evidence.py --base-dir /tmp/sidebar-proof/.t3 \ - --workspace /tmp/sidebar-proof/workspace [--empty] - -Start the server once to migrate an empty isolated home, then stop it first. -Restart with T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=false so startup does not -create an unrelated project and fourth thread. -This fixture creates no event history and must not prove backend behavior. -Use identical workspace, settings, bindings and a fixed browser clock for pairs. -""" - -import argparse -import json -import os -from pathlib import Path -import sqlite3 - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--base-dir", type=Path, required=True) - parser.add_argument("--workspace", type=Path, required=True) - parser.add_argument("--empty", action="store_true") - args = parser.parse_args() - base = args.base_dir.resolve() - if base == (Path.home() / ".t3").resolve() or (base / "userdata").is_symlink(): - parser.error("Use a copied, isolated home, never the live T3 home.") - db = base / "userdata/statev2.sqlite" - if db.is_symlink(): - parser.error("The isolated database must be a copy, never a symlink.") - if not db.is_file(): - parser.error("Initialize an empty isolated home with the server first.") - try: - is_live_db = db.samefile(Path.home() / ".t3/userdata/statev2.sqlite") - except FileNotFoundError: - is_live_db = False - if is_live_db: - parser.error("The isolated database must be a copy, never a hardlink.") - runtime_file = base / "userdata/server-runtime.json" - if runtime_file.is_file(): - runtime = json.loads(runtime_file.read_text()) - try: - os.kill(runtime["pid"], 0) - except ProcessLookupError: - pass - else: - parser.error("Stop the isolated server before seeding its database.") - workspace = args.workspace.resolve(strict=True) - if not workspace.is_dir(): - parser.error("Workspace must be a directory.") - - with sqlite3.connect(db) as connection: - # Refuse existing work, including runnable effects, rather than clearing it. - for table in ( - "orchestration_v2_projection_messages", - "orchestration_v2_projection_runs", - "orchestration_v2_projection_runtime_requests", - "orchestration_v2_effect_outbox", - "scheduled_tasks", - ): - if connection.execute(f"SELECT count(*) FROM {table}").fetchone()[0]: - parser.error(f"Expected empty synthetic state: {table} is populated.") - project, project_title = "shortcut-fixtures", "Shortcut fixtures" - # Only rows this script writes may be replaced; match them exactly. - if connection.execute( - "SELECT count(*) FROM orchestration_v2_projection_threads WHERE NOT " - "(thread_id IN ('shortcut-fixture-1','shortcut-fixture-2','shortcut-fixture-3') " - "AND project_id IS ?)", - (project,), - ).fetchone()[0]: - parser.error("Refusing to replace nonfixture threads.") - if connection.execute( - "SELECT count(*) FROM projection_projects " - "WHERE NOT (project_id IS ? AND title IS ?)", - (project, project_title), - ).fetchone()[0]: - parser.error("Refusing to replace nonfixture projects.") - - clock = "2026-10-22T08:00:00.000Z" - connection.execute("DELETE FROM orchestration_v2_projection_threads") - connection.execute("DELETE FROM projection_projects") - connection.execute( - "INSERT INTO projection_projects " - "(project_id,title,workspace_root,scripts_json,created_at,updated_at) " - "VALUES (?,?,?,?,?,?)", - (project, project_title, str(workspace), "[]", clock, clock), - ) - for index, title in enumerate(() if args.empty else ("Alpha", "Beta", "Gamma"), 1): - thread = f"shortcut-fixture-{index}" - payload = dict( - id=thread, projectId=project, title=f"Thread {title}", - createdBy="system", creationSource="server", - providerInstanceId="codex", - modelSelection=dict(instanceId="codex", model="gpt-6-astra"), - runtimeMode="full-access", interactionMode="default", - branch=None, worktreePath=None, pullRequests=[], - activeProviderThreadId=None, forkedFrom=None, - lineage=dict(parentThreadId=None, relationshipToParent=None, rootThreadId=thread), - createdAt=clock, updatedAt=clock, lastVisitedAt=clock, - archivedAt=None, deletedAt=None, settledOverride=None, settledAt=None, - snoozedUntil=None, snoozedAt=None, activeOrderKey=str(index), - ) - connection.execute( - "INSERT INTO orchestration_v2_projection_threads " - "(thread_id,project_id,title,default_provider,provider_instance_id," - "runtime_mode,interaction_mode,created_at,updated_at,payload_json) " - "VALUES (?,?,?,?,?,?,?,?,?,?)", - (thread, project, payload["title"], "codex", "codex", "full-access", - "default", clock, clock, json.dumps(payload)), - ) - print(f"Seeded {0 if args.empty else 3} synthetic stopped threads in {db}") - - -if __name__ == "__main__": - main() From 61ff85cd27395e7b0965c8fb333d5577c3cae83b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 01:29:10 +0000 Subject: [PATCH 7/9] test(web): closed mobile sidebar sheet keeps its contents mounted AI-assisted; verified with the tests and tools listed above. --- .../components/ui/sidebar.browser.test.tsx | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/web/src/components/ui/sidebar.browser.test.tsx b/apps/web/src/components/ui/sidebar.browser.test.tsx index 3e1d24db40ed8..91279001c8110 100644 --- a/apps/web/src/components/ui/sidebar.browser.test.tsx +++ b/apps/web/src/components/ui/sidebar.browser.test.tsx @@ -130,3 +130,33 @@ it("keeps the mobile sheet closed and leaves the saved desktop state alone", asy .toHaveAttribute("aria-pressed", "false"); localStorage.removeItem(storageKey); }); + +function MobileSheetMountedProbe() { + const { mobileSheetMounted } = useSidebar(); + return {String(mobileSheetMounted)}; +} + +it("keeps closed mobile sheet contents mounted and reports the sheet only while it shows", async () => { + await page.viewport(390, 844); + await using screen = await render( + + + Sheet contents + + + + , + { router: false /* no routes involved */ }, + ); + const sheetMounted = screen.getByLabelText("Sheet mounted"); + // Window shortcuts registered by sidebar children only work while they stay mounted. + expect(document.querySelector('[data-mobile="true"]')?.textContent).toContain("Sheet contents"); + await expect.element(sheetMounted).toHaveTextContent("false"); + + await userEvent.click(screen.getByRole("button", { name: "Toggle Sidebar" })); + await expect.element(sheetMounted).toHaveTextContent("true"); + + await userEvent.keyboard("{Escape}"); + await expect.element(sheetMounted).toHaveTextContent("false"); + expect(document.querySelector('[data-mobile="true"]')?.textContent).toContain("Sheet contents"); +}); From b8f5245bf74cc1b7362c4529df71b81ca7c024ae Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 01:47:16 +0000 Subject: [PATCH 8/9] fix(web): opening the narrow sidebar still scrolls to the open thread The closed sheet now keeps rows mounted but hidden, so the active-row reveal ran while the row had no box and was used up. Wait for the row to show before spending it. AI-assisted; verified with the tests and tools listed above. --- .../sidebar/routeReveal.browser.test.tsx | 28 ++++++++++++++++++- .../web/src/components/sidebar/routeReveal.ts | 15 +++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/sidebar/routeReveal.browser.test.tsx b/apps/web/src/components/sidebar/routeReveal.browser.test.tsx index a87333e40ff08..90a8a0d8826db 100644 --- a/apps/web/src/components/sidebar/routeReveal.browser.test.tsx +++ b/apps/web/src/components/sidebar/routeReveal.browser.test.tsx @@ -1,7 +1,8 @@ import { describe, expect, it, vi } from "vite-plus/test"; -import { userEvent } from "vite-plus/test/browser"; +import { page, userEvent } from "vite-plus/test/browser"; import { render } from "../../../test/render"; +import { Sidebar, SidebarProvider, SidebarTrigger, useSidebar } from "../ui/sidebar"; import { type SidebarRouteReveal, useActiveRowReveal } from "./routeReveal"; const ROW_HEIGHT_PX = 24; @@ -28,6 +29,12 @@ function RevealList(props: { ); } +// Reads the sidebar context like the real thread list, so opening the sheet re-renders it. +function SheetRevealList(props: Parameters[0]) { + useSidebar(); + return ; +} + const rowKeys = (count: number) => Array.from({ length: count }, (_, index) => `thread-${index}`); const newReveal = (): SidebarRouteReveal => ({ observedKey: null, pendingKey: null }); @@ -141,4 +148,23 @@ describe("useActiveRowReveal", () => { ); await expect.element(screen.getByText("thread-40", { exact: true })).toBeInViewport(); }); + + it("reveals the open thread when the closed narrow sheet opens", async () => { + await page.viewport(390, 844); + const reveal = newReveal(); + await using screen = await render( + + + + + + , + // No router: the route arrives as the activeKey prop. + { router: false }, + ); + + await userEvent.click(screen.getByRole("button", { name: "Toggle Sidebar" })); + + await expect.element(page.getByText("thread-40", { exact: true })).toBeInViewport(); + }); }); diff --git a/apps/web/src/components/sidebar/routeReveal.ts b/apps/web/src/components/sidebar/routeReveal.ts index f88433577581b..cfa1965d1337c 100644 --- a/apps/web/src/components/sidebar/routeReveal.ts +++ b/apps/web/src/components/sidebar/routeReveal.ts @@ -1,5 +1,7 @@ import { useRef } from "react"; +import { observeResize } from "~/lib/observeResize"; + import { filterSidebarV2VisibleThreads } from "../Sidebar.logic"; // AppSidebarLayout owns this so drawer and Settings remounts preserve the chosen project scope. @@ -32,10 +34,20 @@ export function completeSidebarRouteReveal(reveal: SidebarRouteReveal): void { // The row can mount after the route, once its shells arrive, so its ref scrolls. export function useActiveRowReveal(reveal: SidebarRouteReveal, routeKey: string | null) { const mountRevealOwed = useRef(true); + const stopWaitingForHiddenRow = useRef<(() => void) | null>(null); pendingSidebarRouteReveal(reveal, routeKey); - return (row: HTMLElement | null, rowKey: string) => { + const revealRow = (row: HTMLElement | null, rowKey: string) => { if (row === null) return; + stopWaitingForHiddenRow.current?.(); if (reveal.pendingKey !== rowKey && !mountRevealOwed.current) return; + // The closed narrow sheet keeps rows mounted but hidden, and opening it does not + // re-render them, so wait for the row to get a box before spending the reveal. + if (row.getClientRects().length === 0) { + stopWaitingForHiddenRow.current = observeResize(row, () => { + if (row.isConnected && row.getClientRects().length > 0) revealRow(row, rowKey); + }); + return; + } completeSidebarRouteReveal(reveal); mountRevealOwed.current = false; // A row under the pointer was just clicked, so it is in view; scrolling it would force a @@ -43,6 +55,7 @@ export function useActiveRowReveal(reveal: SidebarRouteReveal, routeKey: string if (row.matches(":hover")) return; row.scrollIntoView({ block: "nearest" }); }; + return revealRow; } type RevealableThread = Parameters[0][number]; From 2b4045c040a78cf8e1a79995ea44b6da5111e89c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 02:05:56 +0000 Subject: [PATCH 9/9] fix(web): a hidden sidebar row no longer stays watched after it unmounts The reveal's wait for a hidden active row is now the row ref's cleanup, so widening past the breakpoint before the sheet opens releases it. AI-assisted; verified with the tests and tools listed above. --- .../components/sidebar/SidebarThreadRow.tsx | 11 ++++++--- .../sidebar/routeReveal.browser.test.tsx | 23 +++++++++++++++++++ .../web/src/components/sidebar/routeReveal.ts | 20 ++++++++-------- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx index 3a50e76d06bda..9f68716ce29fb 100644 --- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx @@ -552,7 +552,7 @@ type SidebarThreadRowProps = { wokeAt: string | null; isActive: boolean; // Set on the active row only; scrolls it into view when a reveal is owed. - revealRef?: ((row: HTMLElement, threadKey: string) => void) | undefined; + revealRef?: ((row: HTMLElement, threadKey: string) => (() => void) | undefined) | undefined; // Unlike isActive, never true for the ancestor standing in for an open // subagent: drafts and PR clicks care about which composer is on screen. isRouteThread: boolean; @@ -660,8 +660,13 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP const { leaseLiveStatus, rowRef: leaseRowRef } = useSidebarRowSubscriptionLease(props.isActive); const { revealRef } = props; const rowRef = (row: HTMLElement | null) => { - if (row !== null) revealRef?.(row, threadKey); - return leaseRowRef(row); + const stopReveal = row === null ? undefined : revealRef?.(row, threadKey); + const releaseLease = leaseRowRef(row); + if (!stopReveal) return releaseLease; + return () => { + stopReveal(); + releaseLease?.(); + }; }; const isRegeneratingTitle = thread.titleRegeneration != null; const localLastVisitedAt = useUiStateStore((state) => state.threadLastVisitedAtById[threadKey]); diff --git a/apps/web/src/components/sidebar/routeReveal.browser.test.tsx b/apps/web/src/components/sidebar/routeReveal.browser.test.tsx index 90a8a0d8826db..a3b9c1f349e30 100644 --- a/apps/web/src/components/sidebar/routeReveal.browser.test.tsx +++ b/apps/web/src/components/sidebar/routeReveal.browser.test.tsx @@ -149,6 +149,29 @@ describe("useActiveRowReveal", () => { await expect.element(screen.getByText("thread-40", { exact: true })).toBeInViewport(); }); + it("stops watching a hidden active row once it unmounts", async () => { + const reveal = newReveal(); + using observe = vi.spyOn(ResizeObserver.prototype, "observe"); + using unobserve = vi.spyOn(ResizeObserver.prototype, "unobserve"); + using disconnect = vi.spyOn(ResizeObserver.prototype, "disconnect"); + await using screen = await render( + , + // No router: the route arrives as the activeKey prop. + { router: false }, + ); + const row = screen.getByText("thread-40", { exact: true }).element(); + expect(observe).toHaveBeenCalledWith(row); + + // A widening viewport unmounts the closed sheet before it ever opens. + await screen.rerender(