fix(diff): keep the collapsed section header in view (#24466)

Collapsing the section the View all diff viewport was inside kept the
scroll anchor's within-section offset, which pointed into the removed
body, so the structural restore landed on later sections. Pin the anchor
to the section header before the collapse is published.

Fixes #20665
This commit is contained in:
Wooseong Kim
2026-10-26 03:50:58 -07:00
committed by GitHub
parent 819d273e27
commit ab62ae7e96
@@ -167,7 +167,13 @@ export default function CombinedDiffViewer({
const toggleSection = useCallback(
(index: number) => {
const shouldLoadAfterExpand = registry.sectionsRef.current[index]?.collapsed ?? false
const section = registry.sectionsRef.current[index]
const shouldLoadAfterExpand = section?.collapsed ?? false
const anchor = restore.scrollAnchorRef.current
if (section && !section.collapsed && anchor?.key === section.key) {
// The offset points into the body being removed; restore would land on later sections.
anchor.offset = 0
}
setSections((prev) =>
prev.map((s, i) => (i === index ? { ...s, collapsed: !s.collapsed } : s))
)
@@ -175,7 +181,7 @@ export default function CombinedDiffViewer({
registry.loadSchedulerRef.current.request(index)
}
},
[registry.loadSchedulerRef, registry.sectionsRef]
[registry.loadSchedulerRef, registry.sectionsRef, restore.scrollAnchorRef]
)
const treeNavigation = useCombinedDiffTreeNavigation({