-
Notifications
You must be signed in to change notification settings - Fork 131
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 anchor reference not cleared on unmount #386
Comments
Wow! Thank you so much for the detailed write up. I haven't had the time to dive in yet, but that is truly amazing! |
Did you actually manage to reproduce this with just 2 markers? In the clusterer example you shared, I can no longer reproduce it when I remove the markerclusterer. I would really like to understand what is happening there and why. An InfoWindow that renders when it doesn't have a map set shouldn't render period and that would be a bug to report to the google maps team. But if you found a solution that makes sense and makes the problem go away, I'll happily accept a PR for this (or I'll do it myself, whatever happens first). |
The bug only seems to occur when used with clustering. As I showed above it seems like when the I've had a quick glance at how the clustering library works and it takes control of rendering all markers if they are clustered or not. So I believe whenever the map changes it recalculates how to render markers (either in a cluster or by itself). My guess is that during this rendering process, as that link between That's a semi informed guess, I could be completely on the wrong track but it seems like it's something along those lines. I'll raise a PR with the fix I've found 😄 |
It looks to me like this has something to do with the fast re-rendering happening in the markerclusterer example. To be honest, the markerclusterer example contains a couple of errors and bad practices that will – when fixed – stop this issue from surfacing (mostly missing memoizations that cause unneeded re-rendering). But now I want to get to the root cause and understand why this infowindow keeps hanging around so I can raise a bug-report with the maps platform team. |
Another thing is that the |
Yeah for my implementation I did start from the clustering example but spent a lot of time trying to fix that code to find a solution to this bug. I used the example code as a base for the sandbox as it was the easiest way to just demo the bug. The sandbox example is a lot more broken than the state I was able to get to before diving in the library code to try to find a fix there but I wasn't able to find a complete fix without modifying the library (not to say one doesn't exist). The best state I could get to without modifying the |
Ok, so here's what I found out:
While debugging, I also found out how we can unset that anchor without accessing undocumented properties or hurting typescripts feelings: |
I reported this to the maps platform team as well: https://issuetracker.google.com/issues/343750849 |
Description
When used with
@googlemaps/markerclusterer
,InfoWindow
s do not seem to correctly clear their anchor reference during component dismount. This causes emptyInfoWindow
s to reappear against markers that have previously had their anchoredInfoWindow
closed.This issue does not seem to occur when you actually click the 'X' to close the
InfoWindow
. Only when clicking from one marker with an openInfoWindow
to another marker and thus opening it'sInfoWindow
and un-mounting the first marker'sInfoWindow
I'm not sure if this is best to post as part of the description however I was able to do some digging to diagnose the issue.
I modified the library source file
info-window.tsx
to add each createdgoogle.maps.InfoWindow
into a global array which I thenconsole.log
ed out during the cleanup function of theuseEffect
When reproducing the bug by opening an

InfoWindow
against one marker and then clicking another marker to open it'sInfoWindow
I was able to see the following logged out:As you can see the first
InfoWindow
in the array still has a value assigned to it'sanchor
property and the bug with an emptyInfoWindow
occursIf I was to repeat the process but close the
InfoWindow
by clicking the 'X' before opening a secondInfoWindow
the following is logged out:Here the first
InfoWindow
'sanchor
prop is correctly set tonull
and no emptyInfoWindow
is presentModifying the cleanup of the
useEffect
to manually set theanchor
tonull
seems to fix the bug. I'm not sure if this is the best solution but it's working for us at the moment.Steps to Reproduce
https://codesandbox.io/p/devbox/jovial-glade-tx888r
Through a lot of extra react state manipulation which involved explicitly resetting the
markers
state to{}
and then adding markers back on the next render I was able to stop the issue happening immediately upon clicking from one marker to another, however the issue would still occur if I:InfoWindow
and opens Marker B'sInfoWindow
)InfoWindow
s appeared for both Marker A and Marker BEnvironment
@vis.gl/[email protected]
it has been happening for us since we started using the library in the0.4
range at the end of last yearVersion 1.64.122 Chromium: 123.0.6312.122
and ChromeVersion 125.0.6422.77
Logs
The text was updated successfully, but these errors were encountered: