From 5776154425ef3dca82b1ea2d993dfa9819c5bd0d Mon Sep 17 00:00:00 2001 From: Ben Hodgson <116538172+BenHodgsonR2R@users.noreply.github.com> Date: Sat, 24 May 2025 05:28:08 +1000 Subject: [PATCH] Fix: React 18 markers (#1224) * disable batching for _onChange listener * correctly reset cache * move flushsync out of lifecycle method --- src/google_map.js | 6 ++++-- src/google_map_markers.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/google_map.js b/src/google_map.js index c47613e..c4f365a 100644 --- a/src/google_map.js +++ b/src/google_map.js @@ -1,7 +1,7 @@ /* eslint-disable import/no-extraneous-dependencies, react/forbid-prop-types, no-console, no-undef */ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import ReactDOM from 'react-dom'; +import ReactDOM, { flushSync } from 'react-dom'; // helpers import GoogleMapMap from './google_map_map'; @@ -703,7 +703,9 @@ class GoogleMap extends Component { this_._onChildMouseMove(); if (this_.markersDispatcher_) { - this_.markersDispatcher_.emit('kON_CHANGE'); + flushSync(() => { + this_.markersDispatcher_.emit('kON_CHANGE'); + }) if (this_.fireMouseEventOnIdle_) { this_.markersDispatcher_.emit('kON_MOUSE_POSITION_CHANGE'); } diff --git a/src/google_map_markers.js b/src/google_map_markers.js index e2fbb66..b672702 100644 --- a/src/google_map_markers.js +++ b/src/google_map_markers.js @@ -93,7 +93,7 @@ export default class GoogleMapMarkers extends Component { this.props.dispatcher.removeListener('kON_CLICK', this._onChildClick); this.props.dispatcher.removeListener('kON_MDOWN', this._onChildMouseDown); - this.dimensionsCache_ = null; + this.dimensionsCache_ = {}; } _getState = () => ({