From 3f786b160543090117ff7859781f0327b7a856f4 Mon Sep 17 00:00:00 2001 From: Ven Korolev Date: Thu, 16 Jan 2025 16:24:41 +0100 Subject: [PATCH] build 2.7.4 --- lib/usePlacesWidget.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/usePlacesWidget.js b/lib/usePlacesWidget.js index e1a9d4e..6f4d974 100644 --- a/lib/usePlacesWidget.js +++ b/lib/usePlacesWidget.js @@ -52,7 +52,6 @@ function usePlacesWidget(props) { var inputRef = (0, _react.useRef)(null); var event = (0, _react.useRef)(null); var autocompleteRef = (0, _react.useRef)(null); - var observerHack = (0, _react.useRef)(null); var languageQueryParam = language ? "&language=".concat(language) : ""; var googleMapsScriptUrl = "".concat(googleMapsScriptBaseUrl, "?libraries=").concat(libraries, "&key=").concat(apiKey).concat(languageQueryParam); var handleLoadScript = (0, _react.useCallback)(function () { @@ -103,21 +102,22 @@ function usePlacesWidget(props) { }, []); // Autofill workaround adapted from https://stackoverflow.com/questions/29931712/chrome-autofill-covers-autocomplete-for-google-maps-api-v3/49161445#49161445 (0, _react.useEffect)(function () { - var _React$version; - // TODO find out why react 18(strict mode) hangs the page loading - if (!(_react.default !== null && _react.default !== void 0 && (_React$version = _react.default.version) !== null && _React$version !== void 0 && _React$version.startsWith("18")) && _utils.isBrowser && window.MutationObserver && inputRef.current && inputRef.current instanceof HTMLInputElement) { - observerHack.current = new MutationObserver(function () { - observerHack.current.disconnect(); + if (_utils.isBrowser && window.MutationObserver && inputRef.current && inputRef.current instanceof HTMLInputElement) { + var observerHack = new MutationObserver(function () { + observerHack.disconnect(); if (inputRef.current) { inputRef.current.autocomplete = inputAutocompleteValue; } }); - observerHack.current.observe(inputRef.current, { + observerHack.observe(inputRef.current, { attributes: true, attributeFilter: ["autocomplete"] }); + return function () { + observerHack.disconnect(); // Cleanup + }; } }, [inputAutocompleteValue]); (0, _react.useEffect)(function () {