Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/@react-aria/utils/src/useResizeObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type useResizeObserverOptionsType<T> = {

export function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>) {
const {ref, onResize} = options;
let raf = useRef(null);
let raf = useRef<number | null>(null);

useEffect(() => {
let element = ref?.current;
Expand All @@ -26,18 +26,16 @@ export function useResizeObserver<T extends Element>(options: useResizeObserverO
};
} else {
const resizeObserverInstance = new window.ResizeObserver((entries) => {
if (raf.current) {
if (raf.current || !Array.isArray(entries) || !entries.length) {
return;
}
// avoid Error - ResizeObserver loop limit exceeded
// it's ok to use a raf, ResizeObservers are already async and now we're just debouncing on frames
raf.current = window.requestAnimationFrame(() => {
raf.current = null;
if (!Array.isArray(entries) || !entries.length) {
return;
}
onResize();
});
// call onResize immediately
onResize();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait so doesn't this re-introduce the issue fixed by #2891? Why would the requestAnimationFrame be needed at all now if it does nothing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh, you're right, it did re-introduce it. I'll revert the original PR and close this one until we can figure out something else.

});

resizeObserverInstance.observe(element);
Expand Down