gribnoysup / react-yandex-maps

Yandex Maps API bindings for React
MIT License
326 stars 114 forks source link

setApi fired when ymaps is not ready yet #312

Open ValeryVS opened 2 years ago

ValeryVS commented 2 years ago

react-yandex-maps 4.4.0

I use YMaps provider in such way

      <YMaps
        query={{
          ns: 'ymaps',
          load: ['package.full', 'overlay.Polygon'].join(','),
          apikey: process.env.REACT_APP_YMAPS_KEY,
          coordorder: 'longlat',
        }}
      >

with ns: 'ymaps', because it's necessary for vector maps.

Strangely, in lates build of my app, this line https://github.com/gribnoysup/react-yandex-maps/blob/master/src/YMaps.js#L41 sometimes fired before this line https://github.com/gribnoysup/react-yandex-maps/blob/master/src/YMaps.js#L79 but ymaps isn't ready at that point. It has only load, modules, ready, vow and __provideBundle. Then ymaps object is provided by Map component render nothing. My custom components with withYmaps HOC also receives uncompleted ymaps object and crush.

ValeryVS commented 2 years ago

It seems, that my app rerenders App component frequently in current build. Which triggers load function from YMaps provider. getPromise function works correct and maps loads only one time. But sometimes load function fired when window.ymaps is in incompleted state.

In that case

ValeryVS commented 2 years ago

Also, may be I misused withYmaps HOC. What exactly second argument waitForApi for? Is it possible to get unready ymaps if waitForApi leaved by default, which is false?