TypeScript
fix(web): changing the sidebar project filter starts the list at the top (#27327)
Igor Makowskie0fa102aa374
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsxindex 01f62b5a544..4fa3f06e717 100644--- a/apps/web/src/components/Sidebar.tsx+++ b/apps/web/src/components/Sidebar.tsx@@ -362,6 +362,10 @@ interface SidebarThreadPartitionInput {readonly clockKey: string;}+function scrollSidebarToTop(content: HTMLElement | null) {+ content?.closest("[data-slot=scroll-area-viewport]")?.scrollTo({ top: 0 });+}+function threadShellKey(thread: Pick<SidebarThreadSummary, "environmentId" | "id">): string {return scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));}@@ -1054,6 +1058,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReveconst [renamingTitle, setRenamingTitle] = useState("");const settlingThreadKeysRef = useRef(new Set<string>());const threadListRef = useRef<HTMLUListElement | null>(null);+ const sidebarContentRef = useRef<HTMLDivElement | null>(null);const dragLabelOffsetRef = useRef(0);const listMotionRef = useRef<ReturnType<typeof createSidebarListMotion> | null>(null);const [dragState, setDragState] = useState<{@@ -1079,9 +1084,11 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReveconst routeThreadKey = routeThreadRef ? scopedThreadKey(routeThreadRef) : null;// A selection made under one scope can hold threads the next scope hides.+ // The viewport outlives the scope and does not anchor, so a new list starts at the top.const setProjectScopeKeys = (keys: readonly string[]) => {clearSelection();setPersistedProjectScopeKeys(keys);+ scrollSidebarToTop(sidebarContentRef.current);};// A scope whose project is gone reads as all projects once every snapshot has// loaded. The stored keys are left alone, so the scope returns with its project.@@ -2977,6 +2984,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve<ThreadContextDragGhost /><SidebarChromeHeader isElectron={isElectron} /><SidebarContent+ ref={sidebarContentRef}className="min-h-full"fixedHeader={<SidebarGroup className="z-[1]">