Skip to content

Commit

Permalink
fix(autoUpdate): avoid initial update in microtask (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Jun 23, 2022
1 parent 0949185 commit 158f1fc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/dom/src/autoUpdate.ts
Expand Up @@ -68,7 +68,14 @@ export function autoUpdate(

let observer: ResizeObserver | null = null;
if (elementResize) {
observer = new ResizeObserver(update);
let initialUpdate = true;
observer = new ResizeObserver(() => {
if (!initialUpdate) {
update();
}

initialUpdate = false;
});
isElement(reference) && !animationFrame && observer.observe(reference);
observer.observe(floating);
}
Expand Down Expand Up @@ -97,9 +104,7 @@ export function autoUpdate(
frameId = requestAnimationFrame(frameLoop);
}

if (!elementResize) {
update();
}
update();

return () => {
ancestors.forEach((ancestor) => {
Expand Down

0 comments on commit 158f1fc

Please sign in to comment.