From bfdf3c63b3326f3f90de369189eefb6d1be2e70a Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 00:45:40 +0000 Subject: [PATCH] fix(web): harden breadcrumb reveal state Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com> --- .../check-run-agents/ui-consistency.md | 1 + .../src/components/files/FileBrowserPanel.tsx | 84 +++++++++++-------- .../src/components/files/FilePreviewPanel.tsx | 10 ++- 3 files changed, 58 insertions(+), 37 deletions(-) diff --git a/.macroscope/check-run-agents/ui-consistency.md b/.macroscope/check-run-agents/ui-consistency.md index e7514834aa..5f24014a8b 100644 --- a/.macroscope/check-run-agents/ui-consistency.md +++ b/.macroscope/check-run-agents/ui-consistency.md @@ -59,6 +59,7 @@ The goal is not to minimize CSS or class counts at any cost. The goal is to put - Preserve runtime top and bottom overflow state. Do not replace dynamic fades with an always-on static mask. - Preserve fade geometry and keep the native scrollbar lane opaque so the track and thumb stay visible and usable. A visually similar mask that fades the scrollbar is a regression. - For path-driven tree actions with flattened directory rows, do not assume that every registered item path is currently visible. Resolve the target through the tree's visible projection before selecting, focusing, or scrolling, and verify intermediate directory actions against a real flattened chain. +- Treat external tree-reveal requests as one-shot events: resolve and validate the visible target without mutating search, focus, or selection, then acknowledge or clear the request after success so component remounts cannot replay stale navigation. - Verify actual scroll behavior when changing virtualizers, masks, overflow ownership, or scrollbar selectors. Source-level class comparison is not enough. ## Visual and layout preservation diff --git a/apps/web/src/components/files/FileBrowserPanel.tsx b/apps/web/src/components/files/FileBrowserPanel.tsx index 6752153f19..b161de2d8f 100644 --- a/apps/web/src/components/files/FileBrowserPanel.tsx +++ b/apps/web/src/components/files/FileBrowserPanel.tsx @@ -33,6 +33,7 @@ interface FileBrowserPanelProps { /** Breadcrumb target to reveal in the tree. An empty path reveals the project root. */ breadcrumbRevealPath: string | null; breadcrumbRevealId: number; + onBreadcrumbRevealHandled: (revealId: number) => void; onOpenFile: (relativePath: string) => void; } @@ -52,6 +53,22 @@ function treePath(entry: ProjectEntry): string { return entry.kind === "directory" ? `${entry.path}/` : entry.path; } +function visibleDirectoryTreePath(entries: readonly ProjectEntry[], directoryPath: string): string { + // Pierre flattens a directory row only while its sole direct child is another directory. + let currentPath = directoryPath; + while (true) { + const prefix = `${currentPath}/`; + const directChildren = entries.filter((entry) => { + if (!entry.path.startsWith(prefix)) return false; + return !entry.path.slice(prefix.length).includes("/"); + }); + if (directChildren.length !== 1 || directChildren[0]?.kind !== "directory") { + return `${currentPath}/`; + } + currentPath = directChildren[0].path; + } +} + function RefreshFilesButton(props: { isPending: boolean; onRefresh: () => void }) { return ( @@ -109,6 +126,7 @@ export default function FileBrowserPanel({ selectedPathRevealId, breadcrumbRevealPath, breadcrumbRevealId, + onBreadcrumbRevealHandled, onOpenFile, }: FileBrowserPanelProps) { const { resolvedTheme } = useTheme(); @@ -343,9 +361,27 @@ export default function FileBrowserPanel({ ? `${breadcrumbRevealPath}/` : breadcrumbRevealPath; const item = itemPath ? (model.getItem(itemPath) ?? model.getItem(breadcrumbRevealPath)) : null; - if ((breadcrumbRevealPath && !item) || (!breadcrumbRevealPath && !treePaths[0])) return; + const firstEntry = entries[0]; + const rootItemPath = firstEntry + ? firstEntry.kind === "directory" + ? visibleDirectoryTreePath(entries, firstEntry.path) + : firstEntry.path + : null; + if ((breadcrumbRevealPath && !item) || (!breadcrumbRevealPath && !rootItemPath)) return; + const visibleItemPath = itemPath + ? entryKind === "directory" + ? visibleDirectoryTreePath(entries, breadcrumbRevealPath) + : itemPath + : null; + if (visibleItemPath && !model.getItem(visibleItemPath)) return; + + handledBreadcrumbRevealRef.current = revealRequest; + syncingSelectionRef.current = true; model.closeSearch(); + for (const path of model.getSelectedPaths()) { + model.getItem(path)?.deselect(); + } const segments = breadcrumbRevealPath.split("/").filter(Boolean); let ancestorPath = ""; @@ -355,47 +391,25 @@ export default function FileBrowserPanel({ if (ancestor && "expand" in ancestor) ancestor.expand(); } - let visibleItemPath: string | null = null; - if (itemPath) { - // Hidden segments in a flattened chain resolve to their visible ancestor, - // so probe descendants until the projected row belongs to the clicked directory. - const candidates = [ - itemPath, - ...(entryKind === "directory" - ? treePaths.filter( - (path) => path !== itemPath && path.startsWith(itemPath) && path.endsWith("/"), - ) - : []), - ]; - for (const candidate of candidates) { - const projectedPath = model.focusNearestPath(candidate); - const matchesTarget = - projectedPath === itemPath || - (entryKind === "directory" && projectedPath?.startsWith(itemPath)); - if (projectedPath && matchesTarget) { - visibleItemPath = projectedPath; - break; - } - } - if (!visibleItemPath) return; - } - - handledBreadcrumbRevealRef.current = revealRequest; - syncingSelectionRef.current = true; - for (const path of model.getSelectedPaths()) { - model.getItem(path)?.deselect(); - } - if (visibleItemPath) { model.getItem(visibleItemPath)?.select(); model.scrollToPath(visibleItemPath, { focus: true, offset: "center" }); - } else if (treePaths[0]) { - model.scrollToPath(treePaths[0], { focus: true, offset: "top" }); + } else if (rootItemPath) { + model.scrollToPath(rootItemPath, { focus: true, offset: "top" }); } + onBreadcrumbRevealHandled(breadcrumbRevealId); queueMicrotask(() => { syncingSelectionRef.current = false; }); - }, [breadcrumbRevealId, breadcrumbRevealPath, entryKinds, model, treePaths]); + }, [ + breadcrumbRevealId, + breadcrumbRevealPath, + entries, + entryKinds, + model, + onBreadcrumbRevealHandled, + treePaths, + ]); // Tag tree drags with the composer mention payload. The row is read from // the composed event path (the tree's shadow root is open), so this does diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsx index f1122a3520..ab7ed8ad13 100644 --- a/apps/web/src/components/files/FilePreviewPanel.tsx +++ b/apps/web/src/components/files/FilePreviewPanel.tsx @@ -786,6 +786,7 @@ export default function FilePreviewPanel({ const [breadcrumbReveal, setBreadcrumbReveal] = useState<{ path: string; id: number } | null>( null, ); + const breadcrumbRevealIdRef = useRef(0); // Reading markdown rendered is a preference, not a property of one file. Keeping // it on the panel meant a thread switch dropped it and forced source back. const [renderMarkdownPreferred, setRenderMarkdownPreferred] = useLocalStorage( @@ -842,8 +843,12 @@ export default function FilePreviewPanel({ } catch (error) { console.error(error); } - setBreadcrumbReveal((current) => ({ path, id: (current?.id ?? 0) + 1 })); + breadcrumbRevealIdRef.current += 1; + setBreadcrumbReveal({ path, id: breadcrumbRevealIdRef.current }); }; + const handleBreadcrumbRevealHandled = useCallback((revealId: number) => { + setBreadcrumbReveal((current) => (current?.id === revealId ? null : current)); + }, []); const handleOpenInBrowser = useCallback(() => { if (!absolutePath || !environmentHttpBaseUrl) return; @@ -896,7 +901,7 @@ export default function FilePreviewPanel({