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

[Bug] Event listener on map initialized by defaultBounds causes warning in console

Open mfavetti opened this issue 1 year ago • 3 comments

Description

Warning in console when initializing a map with defaultBounds and adding an event listener:

main.js:169 [createEvent] at least one of the values from the map returned undefined. This is not expected to happen. Please report an issue at https://github.com/visgl/react-google-maps/issues/new

Steps to Reproduce

import React from 'react';
import {
  APIProvider,
  Map,
} from '@vis.gl/react-google-maps';

import './App.css';

const API_KEY = '';
const MAP_ID = '';

export default function MyApp() {
  return (
    <APIProvider apiKey={API_KEY}>
      <Map
        id="map"
        mapId={MAP_ID}
        defaultBounds={{north: 45, south: 0, east: 0, west: 45}}
        onCenterChanged={() => {console.log('center changed')}}
      />
    </APIProvider>
  );
}

Environment

  • Library version: 1.2.0
  • Google maps version: weekly
  • Browser and Version: Chrome 129.0.6668.70
  • OS: Mint 22

Logs

main.js:169 [createEvent] at least one of the values from the map returned undefined. This is not expected to happen. Please report an issue at https://github.com/visgl/react-google-maps/issues/new
createMapEvent	@	use-map-events.ts:104
(anonymous)	@	use-map-events.ts:66
_.nk	@	main.js:169
tk	@	main.js:170
_.rk.set	@	main.js:294
(anonymous)	@	main.js:177
d	@	map.js:23
iC	@	map.js:24
(anonymous)	@	main.js:414
Promise.then		
fn.fitBounds	@	main.js:414
(anonymous)	@	use-map-instance.ts:157
commitHookEffectListMount	@	react-dom.development.js:23189
commitPassiveMountOnFiber	@	react-dom.development.js:24965
commitPassiveMountEffects_complete	@	react-dom.development.js:24930
commitPassiveMountEffects_begin	@	react-dom.development.js:24917
commitPassiveMountEffects	@	react-dom.development.js:24905
flushPassiveEffectsImpl	@	react-dom.development.js:27078
flushPassiveEffects	@	react-dom.development.js:27023
(anonymous)	@	react-dom.development.js:26808
workLoop	@	scheduler.development.js:266
flushWork	@	scheduler.development.js:239
performWorkUntilDeadline	@	scheduler.development.js:533
Show less

mfavetti avatar Sep 27 '24 00:09 mfavetti

This prevents the warning:

<Map
        id="map"
        mapId={MAP_ID}
        defaultBounds={{north: 45, south: 0, east: 0, west: 45}}
        onCenterChanged={() => {console.log('center changed')}}
        defaultCenter={{lat: 0, lng: 0}}
        defaultZoom={1}
      />

mfavetti avatar Sep 27 '24 00:09 mfavetti

I tried some other events and so far onCenterChanged is the only one I can reproduce with.

mfavetti avatar Sep 27 '24 00:09 mfavetti

Thanks! The official documentation doesn't have any information on why the types for map.center etc are specified as "might be undefined" and in about ten years with the maps API, I never encountered a situation where they were in fact undefined. That is why I added that error-message so I can finally learn in which situation that will happen :)

I'll figure out how we can prevent that from being a problem...

usefulthink avatar Oct 01 '24 13:10 usefulthink