Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mfavetti opened this issue Sep 27, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mfavetti
Copy link

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 mfavetti added the bug Something isn't working label Sep 27, 2024
@mfavetti
Copy link
Author

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
Copy link
Author

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

@usefulthink
Copy link
Collaborator

usefulthink commented Oct 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants