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

MarkerClustererF does not work in Strictmode

Open gerasimosgakis opened this issue 1 year ago • 3 comments

Issue template

You can donate or became a sponsor https://opencollective.com/react-google-maps-api#category-CONTRIBUTE

If you want to ask question, please ask it in Github Discussions, Spectrum.chat or Slack channel

Please do not post unformatted code into issues, and please do not ask questions. Only real issues, PR's or feature requests are allowed. Minimal reproduction in codesandbox.io is required.

Please provide an explanation of the issue

When using MarkerClustererF in Strict Mode - no markers or clusters are rendered.

Your Environment

os: windows

node --version: 20.3.2

react version: 18.2.0

@react-google-maps/api version: 2.18.1

How does it behave?

No clusters or markers are displayed on the map in strict mode.

How should it behave correctly?

Clusters and markers should be displayed on the map in strict mode

Basic implementation of incorrect behavior in codesandbox.com

https://codesandbox.io/s/gifted-joana-8wt3ld

gerasimosgakis avatar Jul 06 '23 09:07 gerasimosgakis

it is repeated issue. your PR is welcome.

JustFly1984 avatar Jul 15 '23 05:07 JustFly1984

Having the same issue.

MarvinVrdoljak avatar Aug 22 '23 08:08 MarvinVrdoljak

I've gotten around this by waiting to render the clusterer after a timeout. This is obviously a hack but at least it works until this is resolved.

 const [isMounted, setIsMounted] = useState(false)
  useEffect(() => {
    if (isMounted || detectedLocations.length < 1) return
    setTimeout(() => {
      setIsMounted(true)
    }, 1000)
  }, [isMounted, detectedLocations, setIsMounted])

Then in the JSX:

 <GoogleMap
        mapContainerStyle={containerStyle}
        center={center}
        zoom={zoom}
        options={options}
        onLoad={handleMapLoad}
      >
        {isMounted ? (
          <>
            <MarkerClustererF
              minimumClusterSize={10}
              styles={[
                {
                  height: 80,
                  width: 80,
                  textColor: '#fff',
                  textSize: 13,
                  url: iconUrlForColor('#0059B3'),
                },
              ]}
            >
            ...

jimjeffers avatar Oct 18 '23 18:10 jimjeffers