From 72cd4a39d2fc9876743416b6d2f2e747a1aec37c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 15 Jun 2026 16:21:52 +0000 Subject: [PATCH] Avoid mutating memoized sidebar registries Co-authored-by: Julius Marminge Co-authored-by: codex --- apps/web/src/components/Sidebar.tsx | 42 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 0f33b7db5c..dd3019c89a 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -3246,29 +3246,27 @@ export default function Sidebar() { dragInProgressRef.current = false; }, []); - const animatedProjectLists = useMemo(() => new WeakSet(), []); - const attachProjectListAutoAnimateRef = useCallback( - (node: HTMLElement | null) => { - if (!node || animatedProjectLists.has(node)) { - return; - } - autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); - animatedProjectLists.add(node); - }, - [animatedProjectLists], - ); + const animatedProjectListsRef = useRef | null>(null); + const attachProjectListAutoAnimateRef = useCallback((node: HTMLElement | null) => { + const animatedProjectLists = + animatedProjectListsRef.current ?? (animatedProjectListsRef.current = new WeakSet()); + if (!node || animatedProjectLists.has(node)) { + return; + } + autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); + animatedProjectLists.add(node); + }, []); - const animatedThreadLists = useMemo(() => new WeakSet(), []); - const attachThreadListAutoAnimateRef = useCallback( - (node: HTMLElement | null) => { - if (!node || animatedThreadLists.has(node)) { - return; - } - autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); - animatedThreadLists.add(node); - }, - [animatedThreadLists], - ); + const animatedThreadListsRef = useRef | null>(null); + const attachThreadListAutoAnimateRef = useCallback((node: HTMLElement | null) => { + const animatedThreadLists = + animatedThreadListsRef.current ?? (animatedThreadListsRef.current = new WeakSet()); + if (!node || animatedThreadLists.has(node)) { + return; + } + autoAnimate(node, SIDEBAR_LIST_ANIMATION_OPTIONS); + animatedThreadLists.add(node); + }, []); const visibleThreads = useMemo( () => sidebarThreads.filter((thread) => thread.archivedAt === null),