You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since v1.8.0 (PR #913), APIProvider runs an effect that unconditionally calls google.maps.Settings.getInstance() once status === APILoadingStatus.LOADED:
In the "API already available" fast-path in useGoogleMapsApiLoader, status is set to LOADEDbeforeimportLibrary('core' / 'maps') has resolved:
if(window.google?.maps?.importLibraryasunknown){if(!serializedApiParams){updateLoadingStatus(APILoadingStatus.LOADED);// <-- fires the Settings effect}awaitPromise.all(librariesToLoad.map(name=>importLibraryCallback(name)));
...
}
When the Settings effect runs, google.maps.importLibrary exists (the bootstrap installed it) but the actual maps/api/js script has not finished loading yet, so google.maps.Settings is undefined and Settings.getInstance() throws:
TypeError: can't access property "getInstance", google.maps.Settings is undefined
This reproduces reliably in production builds and is mostly invisible in dev, presumably because of scheduling slack and StrictMode double-mount timing differences.
The effect runs regardless of whether fetchAppCheckToken is provided (the effect has no early-return on fetchAppCheckToken === undefined), so there is no userland workaround — omitting the prop does not skip Settings.getInstance().
Suggested fix
Defer the LOADED status update until importLibrary actually resolves in the fast-path, e.g.:
Or, as a defensive fallback, guard the Settings effect:
if(!google.maps.Settings)return;
Steps to Reproduce
Mount <APIProvider apiKey={...}> at the root of a production Vite + React 19 app (SSR or CSR both reproduce).
Don't pass fetchAppCheckToken.
Observe TypeError: can't access property "getInstance", google.maps.Settings is undefined shortly after the provider mounts.
Also reproducible when another component has already caused google.maps.importLibrary to be installed (for example @react-google-maps/api's useJsApiLoader) but the maps script has not finished loading yet.
Description
Since v1.8.0 (PR #913),
APIProviderruns an effect that unconditionally callsgoogle.maps.Settings.getInstance()oncestatus === APILoadingStatus.LOADED:In the "API already available" fast-path in
useGoogleMapsApiLoader,statusis set toLOADEDbeforeimportLibrary('core' / 'maps')has resolved:When the Settings effect runs,
google.maps.importLibraryexists (the bootstrap installed it) but the actualmaps/api/jsscript has not finished loading yet, sogoogle.maps.SettingsisundefinedandSettings.getInstance()throws:This reproduces reliably in production builds and is mostly invisible in dev, presumably because of scheduling slack and StrictMode double-mount timing differences.
The effect runs regardless of whether
fetchAppCheckTokenis provided (the effect has no early-return onfetchAppCheckToken === undefined), so there is no userland workaround — omitting the prop does not skipSettings.getInstance().Suggested fix
Defer the
LOADEDstatus update untilimportLibraryactually resolves in the fast-path, e.g.:Or, as a defensive fallback, guard the Settings effect:
Steps to Reproduce
<APIProvider apiKey={...}>at the root of a production Vite + React 19 app (SSR or CSR both reproduce).fetchAppCheckToken.TypeError: can't access property "getInstance", google.maps.Settings is undefinedshortly after the provider mounts.Also reproducible when another component has already caused
google.maps.importLibraryto be installed (for example@react-google-maps/api'suseJsApiLoader) but the maps script has not finished loading yet.Environment
versionprop passed)Logs
Workaround
Pin
@vis.gl/react-google-mapsto1.7.1, which predates PR #913.