fix(map): stabilize layers menu and offline cache UX
This commit is contained in:
@@ -107,7 +107,32 @@ export function Dropdown({
|
||||
useLayoutEffect(() => {
|
||||
if (!isOpen) return;
|
||||
updatePosition();
|
||||
}, [isOpen, updatePosition]);
|
||||
|
||||
const surface = surfaceRef.current;
|
||||
const anchor = anchorElement ?? triggerElement;
|
||||
if (!surface || typeof ResizeObserver === "undefined") {
|
||||
const frame = window.requestAnimationFrame(updatePosition);
|
||||
return () => window.cancelAnimationFrame(frame);
|
||||
}
|
||||
|
||||
let frame: number | null = null;
|
||||
const schedulePositionUpdate = () => {
|
||||
if (frame !== null) return;
|
||||
frame = window.requestAnimationFrame(() => {
|
||||
frame = null;
|
||||
updatePosition();
|
||||
});
|
||||
};
|
||||
const resizeObserver = new ResizeObserver(schedulePositionUpdate);
|
||||
resizeObserver.observe(surface);
|
||||
if (anchor) resizeObserver.observe(anchor);
|
||||
schedulePositionUpdate();
|
||||
|
||||
return () => {
|
||||
resizeObserver.disconnect();
|
||||
if (frame !== null) window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [anchorElement, isOpen, triggerElement, updatePosition]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
Reference in New Issue
Block a user