maslianok / react-resize-detector

A Cross-Browser, Event-based, Element Resize Detection for React
http://maslianok.github.io/react-resize-detector/
MIT License
1.25k stars 91 forks source link

Size data is undefined when component is in a background browser tab. #122

Closed misaelgaray closed 3 years ago

misaelgaray commented 3 years ago

I'm using the hoc withResizeDetector in a component which takes a while to be mounted (Is rendered after an async task finishes). Once mounted the state is updated in componentDidMount calling componentDidUpdate where I want to use the with and height. The issue is that if I'm not in the browser tab, or if the browser is minimized, or browser is in other windows desktop when the componentDidUpdate is reached then the size data (width, height, ref) is undefined.
Its also undefined in componentDidMount although I don't need the size data there. Using Chrome, Opera and last versions of react-resize-detector. Thanks.

maslianok commented 3 years ago

Hi @misaelgaray Thanks for the detailed explanation.

I hope I found the problem. I use requestAnimationFrame as an optimization to not overload components with onResize events. But according to the raf specification:

requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden