Fix sidebar project reveal: stabilize callbacks and add retry loop

- Wrap requestSidebarProjectReveal and completeSidebarProjectReveal in
  useCallback to prevent unstable function identity from resetting the
  reveal effect on every CommandPalette re-render.
- Replace single requestAnimationFrame with a retry loop (up to 20
  frames) so the reveal completes even if projectHeaderRef is not yet
  available on the first frame.
This commit is contained in:
Cursor Agent committed 2026-06-20 04:42:47 +00:00
1 parent 22cb3451c4
commit 4501ba47ce
2 files changed
+24 -10

No files matched your search

+4 -4
View File
@@ -376,18 +376,18 @@ export function CommandPalette({ children }: { children: ReactNode }) {
const nextSidebarProjectRevealRequestIdRef = useRef(0);
const [sidebarProjectRevealRequest, setSidebarProjectRevealRequest] =
useState<SidebarProjectRevealRequest | null>(null);
function requestSidebarProjectReveal(projectRef: ScopedProjectRef): void {
const requestSidebarProjectReveal = useCallback((projectRef: ScopedProjectRef): void => {
nextSidebarProjectRevealRequestIdRef.current += 1;
setSidebarProjectRevealRequest({
requestId: nextSidebarProjectRevealRequestIdRef.current,
projectRef,
});
}
function completeSidebarProjectReveal(requestId: number): void {
}, []);
const completeSidebarProjectReveal = useCallback((requestId: number): void => {
setSidebarProjectRevealRequest((current) =>
current?.requestId === requestId ? null : current,
);
}
}, []);
const routeTarget = useParams({
strict: false,
select: (params) => resolveThreadRouteTarget(params),
+20 -6
View File
@@ -1179,17 +1179,31 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
return;
}
const frame = window.requestAnimationFrame(() => {
const revealId = projectRevealRequestId;
let cancelled = false;
let frameId: number;
let attempts = 0;
const maxAttempts = 20;
function tryScroll() {
if (cancelled) return;
const projectHeader = projectHeaderRef.current;
if (!projectHeader) {
if (projectHeader) {
scrollSidebarProjectIntoView(projectHeader);
completeProjectReveal(revealId);
return;
}
scrollSidebarProjectIntoView(projectHeader);
completeProjectReveal(projectRevealRequestId);
});
attempts++;
if (attempts < maxAttempts) {
frameId = window.requestAnimationFrame(tryScroll);
}
}
frameId = window.requestAnimationFrame(tryScroll);
return () => {
window.cancelAnimationFrame(frame);
cancelled = true;
window.cancelAnimationFrame(frameId);
};
}, [completeProjectReveal, projectRevealRequestId]);
const sidebarThreads = useThreadShellsForProjectRefs(project.memberProjectRefs);