@dloizides/ui-layout 1.26.1 → 1.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -454,6 +454,10 @@ function observeLayout(node, onChange) {
454
454
  observer.observe(document.body);
455
455
  return observer;
456
456
  }
457
+ function isSameRect(a, b) {
458
+ if (a === null || b === null) return a === b;
459
+ return a.top === b.top && a.left === b.left && a.width === b.width && a.bottom === b.bottom;
460
+ }
457
461
  function useAnchorTracking(containerRef, onOutOfView) {
458
462
  const [rect, setRect] = useState(() => readAnchorRect(containerRef));
459
463
  useLayoutEffect(() => {
@@ -465,7 +469,7 @@ function useAnchorTracking(containerRef, onOutOfView) {
465
469
  frame = null;
466
470
  if (isDisposed) return;
467
471
  const next = readAnchorRect(containerRef);
468
- setRect(next);
472
+ setRect((previous) => isSameRect(previous, next) ? previous : next);
469
473
  const isHidden = next !== null && isAnchorHidden(next, readClipBounds(toDomNode(containerRef)), MIN_VISIBLE_PX);
470
474
  if (hasMeasured && isHidden) onOutOfView();
471
475
  hasMeasured = true;