Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: popover keeps its position object when a scroll moved nothing

This commit is contained in:
iris 2026-10-12 00:21:38 +02:00
commit 5c15580060

View file

@ -54,10 +54,13 @@ export function Popover({
const r = anchor.getBoundingClientRect();
const width = ref.current?.offsetWidth ?? 0;
const maxLeft = window.innerWidth - width - EDGE_PX;
setPos({
top: r.bottom + GAP_PX,
left: Math.max(EDGE_PX, Math.min(r.left, maxLeft)),
});
const top = r.bottom + GAP_PX;
const left = Math.max(EDGE_PX, Math.min(r.left, maxLeft));
// Scrolling anywhere (the streaming terminal included) calls this; keep
// the old object when nothing moved so the subtree does not re-render.
setPos((prev) =>
prev && prev.top === top && prev.left === left ? prev : { top, left },
);
}
place();
window.addEventListener("scroll", place, true);