google-map-react icon indicating copy to clipboard operation
google-map-react copied to clipboard

Fix: React 18 markers

Open BenHodgsonR2R opened this issue 1 year ago • 12 comments

Issue: (https://github.com/google-map-react/google-map-react/issues/1223)

This pull request addresses an issue with the markers rendering incorrectly using React ^18.

The issues were:

  1. StrictMode behaves differently, which exposes an issue with the dimensionsCache property in componentWillUnmount. https://react.dev/blog/2022/03/29/react-v18#new-strict-mode-behaviors
  2. Batched updates, causing flickering with the markers when the map is repositioned or zoomed. Resolved by opting out of automatic batching for the marker state updates (via flushSync). https://react.dev/blog/2022/03/29/react-v18#new-feature-automatic-batching

BenHodgsonR2R avatar May 03 '24 05:05 BenHodgsonR2R

+1 👍 for this

AaronLayton avatar May 08 '24 16:05 AaronLayton

@itsmichaeldiego This really needs to be merged. Otherwise, this library will naturally die.

managervcf avatar May 09 '24 07:05 managervcf

+1 for this to be merged

rubberbandage avatar May 12 '24 13:05 rubberbandage

+1 to merge this...

Mbes9 avatar May 15 '24 14:05 Mbes9

+1

RobotScribe avatar May 16 '24 01:05 RobotScribe

+1

maanenh avatar May 20 '24 09:05 maanenh

To avoid this warning: Warning: flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task.

I've moved flushSync out of the lifecycle method, the fix has the same effect, but without the warning in console now.

Relevant commit

BenHodgsonR2R avatar May 24 '24 02:05 BenHodgsonR2R

Any update on when this is going to get merged? @karldanninger @itsmichaeldiego

icaaq avatar May 27 '24 09:05 icaaq

It won't be. The library is abandoned.

Is this PR available in a fork anywhere?

wescopeland avatar Jun 07 '24 13:06 wescopeland

Is this project still alive? This pull request will fix a very bad bug, please marge it

MicheleFatticcioni avatar Jun 19 '24 12:06 MicheleFatticcioni

I've created a fork that contains this branch's changes:

npm install --save google-map-react-concurrent2

wescopeland avatar Jun 19 '24 13:06 wescopeland

If you need this now and can't wait for the merge, you can create a patch and apply it to your local project.

1. Clone the repository

git clone https://github.com/google-map-react/google-map-react.git
cd google-map-react

2. Download the PR as a Patch File

Open the pull request URL and add .patch to the end of it, to download it as a patch file:

Original PR URL: https://github.com/google-map-react/google-map-react/pull/1224 Patch URL: https://github.com/google-map-react/google-map-react/pull/1224.patch

Save the patch file (1224.patch) to the directory of your local copy of google-map-react.

3. Apply the Patch

Inside your local copy of google-map-react, apply the patch using the git apply command:

git apply 1224.patch

4. Commit Your Changes

Add and commit your changes:

git add .
git commit -m "Apply fixes from pull request #1224"

5. Create a Tarball from Your Package

Create a tarball of your patched package:

pnmp pack

This will generate a file like google-map-react-2.2.1.tgz.

6. Use the Tarball in Your Project

Copy the tarball file (google-map-react-2.2.1.tgz) to your project directory and update your package.json to use it:

"dependencies": {
  "google-map-react": "file:./google-map-react-2.2.1.tgz",
  // your other dependencies...
}

7. Install the Package

pnpm i

After applying this, everything works again, I see all markers and the markers don't flicker or jump around when I move the map. Thank you @BenHodgsonR2R and maybe @karldanninger or @itsmichaeldiego can look into this too. Thanks

ciruz avatar Jul 10 '24 09:07 ciruz

Any updates on merging this?

camro avatar Dec 10 '24 04:12 camro

My recommendation is to either:

  • Patch, as guided here: https://github.com/google-map-react/google-map-react/pull/1224#issuecomment-2219951120
  • Or migrate to https://github.com/visgl/react-google-maps which is actively maintained.

I don't think it's worth relying on contributions here.

The project I've been working on that previously used this library has been migrated to https://github.com/visgl/react-google-maps and we haven't faced any issues with React 18.

BenHodgsonR2R avatar Dec 10 '24 04:12 BenHodgsonR2R

Hello @karldanninger @itsmichaeldiego, could you please ship this piece at least as beta or alpha release!

3imed-jaberi avatar Dec 26 '24 01:12 3imed-jaberi

Any updates on this?

JJSLIoT avatar May 06 '25 11:05 JJSLIoT

Deployed in v2.2.5, let me know if it works, thanks

itsmichaeldiego avatar May 23 '25 19:05 itsmichaeldiego