fix(web): serialize root breadcrumb reveal

Co-authored-by: Exotic <[email protected]>
This commit is contained in:
t3-code[bot]andExotic committed 2026-08-16 01:23:44 +00:00
1 parent 94a2fd88ce
commit 1b0f5978b3
2 files changed
+32 -11

No files matched your search

@@ -59,7 +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. A project-root reveal should scroll the tree viewport itself and preserve the current selected item; raw entry order is not visible row order.
- 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. A project-root reveal should scroll the tree viewport itself and preserve the current selected item; raw entry order is not visible row order. If a reveal opens and mounts the tree, suppress the normal selected-file reveal while the request is pending and wait for the real virtualized viewport before scrolling.
- Verify actual scroll behavior when changing virtualizers, masks, overflow ownership, or scrollbar selectors. Source-level class comparison is not enough.
## Visual and layout preservation
@@ -144,6 +144,8 @@ export default function FileBrowserPanel({
const treeSelectionPathRef = useRef<string | null>(null);
const handledRevealRef = useRef<{ path: string; revealId: number } | null>(null);
const handledBreadcrumbRevealRef = useRef<{ path: string; revealId: number } | null>(null);
const pendingBreadcrumbRevealPathRef = useRef(breadcrumbRevealPath);
pendingBreadcrumbRevealPathRef.current = breadcrumbRevealPath;
// The tree renders rows in shadow DOM and its anchor rect is unreliable, so
// capture the right-click position ourselves; contextmenu is a composed
@@ -291,6 +293,10 @@ export default function FileBrowserPanel({
handledRevealRef.current = null;
return;
}
// Opening the explorer from a breadcrumb mounts this effect before the
// breadcrumb reveal below. Let the explicit breadcrumb request own the
// initial focus and scroll instead of centering the open file first.
if (pendingBreadcrumbRevealPathRef.current !== null) return;
const revealRequest = { path: selectedPath, revealId: selectedPathRevealId };
const handledReveal = handledRevealRef.current;
// Entry refreshes rebuild treePaths while the same preview stays open.
@@ -354,20 +360,37 @@ export default function FileBrowserPanel({
return;
}
const entryKind = breadcrumbRevealPath ? entryKinds.get(breadcrumbRevealPath) : "directory";
if (breadcrumbRevealPath === "") {
let frameId: number | null = null;
let attemptsRemaining = 120;
const revealProjectRoot = () => {
const scrollContainer = model
.getFileTreeContainer()
?.shadowRoot?.querySelector<HTMLElement>("[data-file-tree-virtualized-scroll]");
if (!scrollContainer) {
attemptsRemaining -= 1;
if (attemptsRemaining > 0) frameId = requestAnimationFrame(revealProjectRoot);
return;
}
handledBreadcrumbRevealRef.current = revealRequest;
model.closeSearch();
scrollContainer.scrollTop = 0;
onBreadcrumbRevealHandled(breadcrumbRevealId);
};
revealProjectRoot();
return () => {
if (frameId !== null) cancelAnimationFrame(frameId);
};
}
const entryKind = entryKinds.get(breadcrumbRevealPath);
if (!entryKind) return;
const itemPath =
entryKind === "directory" && breadcrumbRevealPath
? `${breadcrumbRevealPath}/`
: breadcrumbRevealPath;
const item = itemPath ? (model.getItem(itemPath) ?? model.getItem(breadcrumbRevealPath)) : null;
const rootScrollContainer =
breadcrumbRevealPath === ""
? model
.getFileTreeContainer()
?.shadowRoot?.querySelector<HTMLElement>("[data-file-tree-virtualized-scroll]")
: null;
if ((breadcrumbRevealPath && !item) || (!breadcrumbRevealPath && !rootScrollContainer)) return;
if (!item) return;
const visibleItemPath = itemPath
? entryKind === "directory"
@@ -396,8 +419,6 @@ export default function FileBrowserPanel({
if (visibleItemPath) {
model.getItem(visibleItemPath)?.select();
model.scrollToPath(visibleItemPath, { focus: true, offset: "center" });
} else if (rootScrollContainer) {
rootScrollContainer.scrollTop = 0;
}
onBreadcrumbRevealHandled(breadcrumbRevealId);
queueMicrotask(() => {