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] InfoWindow automatically closes when the map moves. #628

Open
Bcavez opened this issue Dec 4, 2024 · 1 comment
Open

[Bug] InfoWindow automatically closes when the map moves. #628

Bcavez opened this issue Dec 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Bcavez
Copy link

Bcavez commented Dec 4, 2024

Description

On version 1.4.2, the InfoWindow automatically closes when the map is moved. Which is particularly annoying because when an InfoWindow is not entirely in the viewport, the map is automatically moved in order to fully show the infowindow, which means that the InfoWindow is opened then instantly closed.

Looking at it, I can see that the onClose event is triggered whenever the map is being moved.
I don't know if this is relevant, but I'm using the infowindow on an advancermarker and there are also clusters on the map.

On version 1.1.3, everything works fine. When opening the InfoWindow, it stays open. When moving the map, it stays open.

Steps to Reproduce

First case:

  1. Add an InfoWindow to an AdvancerMarker like described in the docs https://visgl.github.io/react-google-maps/docs/api-reference/components/info-window#infowindow-attached-to-marker
  2. Click on the InfoWindow
  3. Move the map, the window is closed.

Second case:

  1. Add an InfoWindow to an AdvancerMarker like described in the docs https://visgl.github.io/react-google-maps/docs/api-reference/components/info-window#infowindow-attached-to-marker
  2. Move the map so that the marker is in a corner and there won't be enough space to display the infowindow
  3. Click on the marker
  4. The infowindow opens then closes instantly after map re-centering

Environment

  • Library version: "@vis.gl/react-google-maps": "1.4.2"
  • Google maps version: weekly
  • Browser and Version: Chrome latest
  • OS: windows 11

Logs

No response

@Bcavez Bcavez added the bug Something isn't working label Dec 4, 2024
@mrMetalWood
Copy link
Collaborator

mrMetalWood commented Dec 4, 2024

Hi @Bcavez, thanks for taking the time to report the issue! It looks like a bug indeed.
At first glance it seems that this effect (https://github.com/visgl/react-google-maps/blob/main/src/components/info-window.tsx#L175-L235) is triggered more often than it should and thus calling infowindow.close() which then triggers the onClose event. The fix should be pretty straight forward. Maybe even just replacing useEffect with useDeepCompareEffect

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