gribnoysup / react-yandex-maps

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

TypeError: Cannot read property 'setCoordinates' of null #217

Open ValeryVS opened 4 years ago

ValeryVS commented 4 years ago

Error text

react-dom.production.min.js:4636 TypeError: Cannot read property 'setCoordinates' of null
    at Function.t.updateObject (react-yandex-maps.esm.js:1054)
    at t.componentDidUpdate (react-yandex-maps.esm.js:1025)
    at react-dom.production.min.js:6326
    at t.unstable_runWithPriority (scheduler.production.min.js:270)
    at Ko (react-dom.production.min.js:2794)
    at ws (react-dom.production.min.js:6105)
    at Es (react-dom.production.min.js:5408)
    at react-dom.production.min.js:2829
    at t.unstable_runWithPriority (scheduler.production.min.js:270)
    at Ko (react-dom.production.min.js:2794)

I use GeoObject

  <GeoObject
    geometry={{
      type: 'Point',
      coordinates: [
        lat,
        lng,
      ],
    }}
    properties={{
      iconContent: small ? undefined : caption,
    }}
    options={{
      preset: small ? 'islands#circleDotIcon' : 'islands#blueStretchyIcon',
    }}
  />

Error goes from BaseGeoObject's updateObject function. https://github.com/gribnoysup/react-yandex-maps/blob/04db88dfe52cfb2d3a07467a6501b407f1ef2ef3/src/geo-objects/BaseGeoObject.js#L81-L100

Shoul I preload some module or something? Or it was just some random glitch?

gribnoysup commented 4 years ago

Please provide a reproduction example, I can't reproduce the issue with provided info:

Edit nice-mendel-qz3l6

ValeryVS commented 4 years ago

Found it. It was not GeoObject's but Polyline's fault. Which is extended from BaseGeoObject too. https://codesandbox.io/s/naughty-elion-m7nfh

For now I'm fixed this with {waypoints && <Polyline.... But this, probably, should be fixed or TypeScript type should be corrected. Now geometry is optional.

export interface GeoObjectProps<G, P = AnyObject, O = AnyObject>
  extends AnyObject {
  geometry?: G;
...
Shokhrukh2606 commented 4 years ago

Can you help to fix this issue gribnoysup i had also this kind of issue when filtering geobjects?

mmarkelov commented 3 years ago

I think this is not related to typescript. I made some investigation on it. So if you pass null or undefined as geometry: https://github.com/gribnoysup/react-yandex-maps/blob/04db88dfe52cfb2d3a07467a6501b407f1ef2ef3/src/geo-objects/BaseGeoObject.js#L48

Yandex Maps will create object without geometry prop and will break updating logic. As workaround you can pass empty array as initial state.