Skip to content

Commit

Permalink
chore(core): revert "fix(core): avoid occasional "ResizeObserver loop…
Browse files Browse the repository at this point in the history
…" error (#1466)"

This reverts commit 7f88e10.
  • Loading branch information
wyze authored and plouc committed Jun 4, 2021
1 parent f0acb81 commit 8a99932
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions packages/core/src/hooks/useMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,20 @@ import ResizeObserver from 'resize-observer-polyfill'

export const useMeasure = () => {
const measureRef = useRef(null)
const animationFrameId = useRef(null)
const [bounds, setBounds] = useState({
left: 0,
top: 0,
width: 0,
height: 0,
})
const [observer] = useState(
() =>
new ResizeObserver(([entry]) => {
// wrap this call in requestAnimationFrame to avoid "Resize Observer loop limit exceeded"
// error in certain situations
animationFrameId.current = requestAnimationFrame(() => {
setBounds(entry.contentRect)
})
})
)
const [observer] = useState(() => new ResizeObserver(([entry]) => setBounds(entry.contentRect)))

useEffect(() => {
if (measureRef.current) {
observer.observe(measureRef.current)
}

return () => {
if (animationFrameId.current) {
cancelAnimationFrame(animationFrameId.current)
}
observer.disconnect()
}
return () => observer.disconnect()
}, [])

return [measureRef, bounds]
Expand Down

0 comments on commit 8a99932

Please sign in to comment.