Skip to content

Commit a303945

Browse files
authored
Revert "fix: Popover is positioned incorrectly when the layout changes (#3427)"
This reverts commit 62b757d.
1 parent 62b757d commit a303945

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/popover/container.tsx

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export default function PopoverContainer({
116116
/*
117117
This is a heuristic. Some layout changes are caused by user clicks (e.g. toggling the tools panel, submitting a form),
118118
and by tracking the click event we can adapt the popover's position to the new layout.
119-
*/
120119
121-
const controller = new AbortController();
120+
TODO: extend this to Enter and Spacebar?
121+
*/
122122

123-
const onClick = async (event: UIEvent | KeyboardEvent) => {
123+
const onClick = (event: UIEvent | KeyboardEvent) => {
124124
if (
125125
// Do not update position if keepPosition is true.
126126
keepPosition ||
@@ -131,29 +131,14 @@ export default function PopoverContainer({
131131
return;
132132
}
133133

134-
// Continuously update the popover position for one second to account for any layout changes
135-
// and animations. On browsers where `requestIdleCallback` is supported,
136-
// this runs only while the CPU is otherwise idle. In other browsers (mainly Safari), we call it
137-
// with a low frequency.
138-
const targetTime = performance.now() + 1_000;
139-
140-
while (performance.now() < targetTime) {
141-
if (controller.signal.aborted) {
142-
break;
143-
}
144-
134+
requestAnimationFrame(() => {
145135
updatePositionHandler();
146-
147-
if (typeof requestIdleCallback !== 'undefined') {
148-
await new Promise(r => requestIdleCallback(r));
149-
} else {
150-
await new Promise(r => setTimeout(r, 50));
151-
}
152-
}
136+
});
153137
};
154138

155139
const updatePositionOnResize = () => requestAnimationFrame(() => updatePositionHandler());
156140
const refreshPosition = () => requestAnimationFrame(() => positionHandlerRef.current());
141+
const controller = new AbortController();
157142

158143
window.addEventListener('click', onClick, { signal: controller.signal });
159144
window.addEventListener('resize', updatePositionOnResize, { signal: controller.signal });

0 commit comments

Comments
 (0)