react-googlemaps icon indicating copy to clipboard operation
react-googlemaps copied to clipboard

Overlay should not draw before it is added to the map

Open shipstar opened this issue 9 years ago • 0 comments

I ran into a bug (I think) with ReactOverlayView. Here's what I think is happening:

  1. MyReactComponent renders a Map component with overlays.
  2. Before the Google Maps JS can add the overlays to the Google Map, MyReactComponent#setState triggers a re-render (because of Flux in my case).
  3. React calls ReactOverlayView#componentDidUpdate, which calls MapOverlayView#draw. (Note that MapOverlayView#add has still not been called.)
  4. MapOverlayView#getProjection returns undefined, so the following error appears: Uncaught TypeError: Cannot read property 'fromLatLngToDivPixel' of undefined

I think the fix is pretty simple -- have ReactOverlayView#componentDidUpdate check whether __node has a _containerElement before drawing (which means that onAdd has been called and drawing is :+1: ).

Pull request incoming, but feel free to push back if there's a better solution.

shipstar avatar Mar 19 '15 18:03 shipstar