From afc20b129785da72bcd35eedb227694e13277f6f Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 9 Apr 2026 23:43:21 +1000 Subject: [PATCH] refactor(google-maps)!: rename googleMaps expose to mapsApi Rename the template-ref expose key on `` from `googleMaps` to `mapsApi`. The old key is preserved as a deprecated alias backed by an accessor that fires a one-shot dev-mode warning, so existing template-ref consumers keep working without breakage. `` gets the same treatment: `overlay` becomes `overlayView`, with `overlay` retained as a deprecated alias. Implementation: - Added `defineDeprecatedAlias` helper in `useGoogleMapsResource` that swaps a data property for an accessor with a one-shot warning - Both call sites wrap the helper in `if (import.meta.dev)` so production builds skip the getter entirely and the alias remains a plain data property pointing at the canonical ref - The `ready` event payload still uses `ScriptGoogleMapsExpose`, so consumers gain `mapsApi` as an additive property without breakage Docs updated: template-ref API table now lists `mapsApi` first and marks `googleMaps` as deprecated; v0->v1 migration guide gains a section showing the rename for both `` and ``. --- .../docs/4.migration-guide/1.v0-to-v1.md | 22 +++ .../google-maps/2.api/1.script-google-maps.md | 3 +- .../GoogleMaps/ScriptGoogleMaps.vue | 33 +++- .../ScriptGoogleMapsOverlayView.vue | 30 +++- .../GoogleMaps/useGoogleMapsResource.ts | 31 ++++ test/unit/google-maps-components.test.ts | 142 +++++++++++++++++- 6 files changed, 251 insertions(+), 10 deletions(-) diff --git a/docs/content/docs/4.migration-guide/1.v0-to-v1.md b/docs/content/docs/4.migration-guide/1.v0-to-v1.md index b9b4ddd2..a4d0f404 100644 --- a/docs/content/docs/4.migration-guide/1.v0-to-v1.md +++ b/docs/content/docs/4.migration-guide/1.v0-to-v1.md @@ -392,6 +392,28 @@ The top-level `center` and `zoom` props on ``{lang="html"} are + ``` +#### Template Ref `googleMaps` Renamed to `mapsApi` + +The `googleMaps` template-ref key on ``{lang="html"} has been renamed to `mapsApi` to better reflect what it holds (the `google.maps` API namespace, not the component itself). The old key still works as a deprecated alias and emits a one-shot dev-mode warning when read. + +```diff + const mapRef = ref() + onMounted(() => { +- console.log(mapRef.value?.googleMaps) ++ console.log(mapRef.value?.mapsApi) + }) +``` + +The same rename applies to ``{lang="html"}: its exposed `overlay` key is now `overlayView`, with `overlay` kept as a deprecated alias. + +```diff + const overlayRef = ref() + onMounted(() => { +- console.log(overlayRef.value?.overlay) ++ console.log(overlayRef.value?.overlayView) + }) +``` + ### Google Maps Static Placeholder ([#673](https://github.com/nuxt/scripts/pull/673)) v1 extracts the built-in static map placeholder into a standalone [``{lang="html"}](/scripts/google-maps/api/static-map) component. This removes the following props from ``{lang="html"}: diff --git a/docs/content/scripts/google-maps/2.api/1.script-google-maps.md b/docs/content/scripts/google-maps/2.api/1.script-google-maps.md index f5febe1a..8262ae94 100644 --- a/docs/content/scripts/google-maps/2.api/1.script-google-maps.md +++ b/docs/content/scripts/google-maps/2.api/1.script-google-maps.md @@ -35,7 +35,8 @@ Access the basic Google Maps instances via a template ref. The exposed object co | Property | Type | Description | |----------|------|-------------| -| `googleMaps` | `Ref`{lang="html"} | The core Maps API library. | +| `mapsApi` | `ShallowRef`{lang="html"} | The core Maps API namespace (`google.maps`). | +| `googleMaps` | `ShallowRef`{lang="html"} | **Deprecated.** Alias for `mapsApi`; emits a dev-mode warning. Slated for removal in a future major version. | | `map` | `ShallowRef`{lang="html"} | The map instance. | | `resolveQueryToLatLng` | `(query) => Promise`{lang="html"} | Geocode an address to coordinates. | | `importLibrary` | `(name) => Promise`{lang="html"} | Load additional Google Maps libraries at runtime. | diff --git a/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue b/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue index 883c9ff7..b3fabf9e 100644 --- a/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +++ b/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMaps.vue @@ -78,7 +78,17 @@ export interface ScriptGoogleMapsProps { export interface ScriptGoogleMapsExpose { /** - * A reference to the loaded Google Maps API, or `undefined` if not yet loaded. + * A reference to the loaded Google Maps API namespace (`google.maps`), or + * `undefined` if not yet loaded. + */ + mapsApi: ShallowRef + /** + * A reference to the loaded Google Maps API namespace, or `undefined` if not + * yet loaded. + * + * @deprecated Use `mapsApi` instead. The `googleMaps` alias will be removed + * in a future major version. + * @see https://scripts.nuxt.com/docs/migration-guide/v0-to-v1 */ googleMaps: ShallowRef /** @@ -147,7 +157,7 @@ import { defu } from 'defu' import { tryUseNuxtApp, useHead, useRuntimeConfig } from 'nuxt/app' import { computed, onBeforeUnmount, onMounted, provide, ref, shallowRef, toRaw, useAttrs, useTemplateRef, watch } from 'vue' import ScriptAriaLoadingIndicator from '../ScriptAriaLoadingIndicator.vue' -import { MAP_INJECTION_KEY, waitForMapsReady, warnDeprecatedTopLevelMapProps } from './useGoogleMapsResource' +import { defineDeprecatedAlias, MAP_INJECTION_KEY, waitForMapsReady, warnDeprecatedTopLevelMapProps } from './useGoogleMapsResource' const props = withDefaults(defineProps(), { // @ts-expect-error untyped @@ -315,14 +325,27 @@ function importLibrary(key: string): Promise { return cached as Promise } -const googleMaps: ScriptGoogleMapsExpose = { +const exposed: ScriptGoogleMapsExpose = { + mapsApi, + // Plain alias for production. In dev, replaced below with a getter that + // emits a one-shot deprecation warning. Both forms return the same + // shallow ref as `mapsApi`. googleMaps: mapsApi, map, resolveQueryToLatLng, importLibrary, } -defineExpose(googleMaps) +if (import.meta.dev) { + defineDeprecatedAlias( + exposed, + 'googleMaps', + 'mapsApi', + '[nuxt-scripts] expose key "googleMaps" is deprecated; use "mapsApi" instead. See https://scripts.nuxt.com/docs/migration-guide/v0-to-v1', + ) +} + +defineExpose(exposed) // Shared InfoWindow group: only one InfoWindow open at a time within this map let activeInfoWindow: google.maps.InfoWindow | undefined @@ -340,7 +363,7 @@ provide(MAP_INJECTION_KEY, { onMounted(() => { watch(isMapReady, (v) => { if (v) { - emits('ready', googleMaps) + emits('ready', exposed) } }) watch(status, (v) => { diff --git a/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue b/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue index 6ab11e8c..160dbced 100644 --- a/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue +++ b/packages/script/src/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue @@ -63,6 +63,14 @@ export interface ScriptGoogleMapsOverlayViewSlots { export interface ScriptGoogleMapsOverlayViewExpose { /** The underlying `OverlayView` instance. */ + overlayView: ShallowRef + /** + * The underlying `OverlayView` instance. + * + * @deprecated Use `overlayView` instead. The `overlay` alias will be + * removed in a future major version. + * @see https://scripts.nuxt.com/docs/migration-guide/v0-to-v1 + */ overlay: ShallowRef /** The current data-state of the overlay, either 'open' or 'closed'. */ dataState: Readonly> @@ -72,7 +80,7 @@ export interface ScriptGoogleMapsOverlayViewExpose {