Skip to content

[Bug] On clicking AdvanceMarker to open InfoWindow, goes into an Infinite loop of rendering on setting markerRef(marker) manually #402

@m-nathani

Description

@m-nathani

Description

I am using the Cluster example the docs with MarkerWithInfoWindow, however there is nothing much i changed for cluster or infowindow from the docs... onClick on the marker should have open the infowindow, but instead to goes in an infinite loop.

Please note that i am setting the markerRef(marker); on the ref of AdvanceMarker manually because i want to support Cluster along with it... it appears to be a standard way to me to set ref to multiple places for marker... however it crashes

const MarkerWithInfoWindow = forwardRef<
  AdvancedMarkerRef,
  AdvancedMarkerProps & {
    point: Point;
    setMarkerRef: (marker: Marker | null, key: number) => void;
  }
>(({ point, setMarkerRef, ...props }, ref) => {
  let [markerRef, marker] = useAdvancedMarkerRef();
  const [infoWindowOpen, setInfoWindowOpen] = useState(false);

  return (
    <>
      <AdvancedMarker
        ref={(marker1) => {
          markerRef(marker1);
          setMarkerRef(marker1, point.key);
        }}
        onClick={(e) => {
          setInfoWindowOpen(true);
        }}
        position={point}
        title={point.name}
        zIndex={50}
        {...props}
      />
      {infoWindowOpen && (
        <InfoWindow anchor={marker} maxWidth={200} onCloseClick={() => setInfoWindowOpen(false)}>
          <code style={{ whiteSpace: 'nowrap' }}>&lt;AdvancedMarker /&gt;</code> combined with an
          Infowindow.
        </InfoWindow>
      )}
    </>
  );
});

Steps to Reproduce

I am using next 14, and this is a client component.

  1. Click on the marker and it goes on an infinite loop and hence the app crashes.

image

Environment

  • Library version: "@vis.gl/react-google-maps": "^1.0.2",
  • Google maps version: 3.57.3a
  • Browser and Version: Chrome 125.0.6422.141 (Official Build) (64-bit)
  • OS: Linux ( Ubuntu )

Logs

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions