react-yandex-maps icon indicating copy to clipboard operation
react-yandex-maps copied to clipboard

TypeError: Cannot read property 'setCoordinates' of null

Open ValeryVS opened this issue 4 years ago • 4 comments

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?

ValeryVS avatar Mar 18 '20 18:03 ValeryVS

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

Edit nice-mendel-qz3l6

gribnoysup avatar Mar 19 '20 11:03 gribnoysup

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;
...

ValeryVS avatar Mar 20 '20 16:03 ValeryVS

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

Shokhrukh2606 avatar Jun 22 '20 16:06 Shokhrukh2606

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.

mmarkelov avatar Oct 12 '20 10:10 mmarkelov