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

Error with window.ResizeObserver constructor on iOS 13.3 #189

Closed adirsation closed 2 years ago

adirsation commented 2 years ago

Safari browser on version 13.3 crashes with typeerror undefined is not a constructor on new window.ResizeObserver

carmnk commented 2 years ago

Same for me. It's simply not supported, see: https://caniuse.com/?search=resize-observer

@maslianok would you accept a PR (which would at least prevent the crash behavior)? Haven't checked the src code yet, maybe I could contribute something during the holidays.

maslianok commented 2 years ago

@adirsation @carmnk Thank you for the feedback!

All versions below 7.0.0 have a build with polyfill, e.g. you can import

import ResizeObserver from 'react-resize-detector/build/withPolyfill';

It uses this polyfill.

Unfortunately, it's not been updated for a long time and caused some problems for other users, but overall it works well.

So in case you need support for older browsers you can use this polyfill. I think something like this should work:

import ResizeObserver from 'resize-observer-polyfill';

if (!window.ResizeObserver) {
    window.ResizeObserver = ResizeObserver;
}
maslianok commented 2 years ago

@maslianok would you accept a PR (which would at least prevent the crash behavior)?

Of course I would accept a PR :) Thank you in advance!

Let me know if you have any questions