Skip to content

Commit 37d3870

Browse files
committed
fix: mark useScript instance as raw
1 parent b65e5db commit 37d3870

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

docs/content/scripts/google-maps/2.api/1.script-google-maps.md

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,17 @@ title: <ScriptGoogleMaps>
44

55
The [`<ScriptGoogleMaps>`{lang="html"}](/scripts/google-maps){lang="html"} component is a wrapper around the [`useScriptGoogleMaps()`{lang="ts"}](/scripts/google-maps/api/use-script-google-maps){lang="ts"} composable. It provides a simple way to embed Google Maps in your Nuxt app.
66

7+
::script-types{script-key="google-maps" filter="ScriptGoogleMaps"}
8+
::
9+
710
It's optimized for performance by using the [Element Event Triggers](/docs/guides/script-triggers#element-event-triggers), only loading the Google Maps when specific elements events happen.
811

912
Before Google Maps loads, it shows a placeholder using [Maps Static API](https://developers.google.com/maps/documentation/maps-static).
1013

1114
By default, it will load on the `mouseenter`, `mouseover`, and `mousedown` events.
1215

13-
## Key Props
14-
15-
| Prop | Type | Default | Description |
16-
|---|---|---|---|
17-
| `apiKey` | `string` | - | Google Maps API key |
18-
| `center` | `LatLngLiteral \| LatLng \| string` | - | Map center (coordinates or query string) |
19-
| `zoom` | `number` | `15` | Map zoom level (0-21). Reactive, takes precedence over `mapOptions.zoom` |
20-
| `mapOptions` | `google.maps.MapOptions` | - | Full map configuration |
21-
| `markers` | `(string \| AdvancedMarkerElementOptions)[]` | - | Quick markers (use SFC components for full control) |
22-
| `trigger` | `ElementScriptTrigger` | `['mouseenter', 'mouseover', 'mousedown']` | When to load the Google Maps script |
23-
| `aboveTheFold` | `boolean` | `false` | Prioritize placeholder image loading |
24-
2516
See the [Facade Component API](/docs/guides/facade-components#facade-components-api) for all props, events, and slots.
2617

27-
## Events
28-
29-
The [`<ScriptGoogleMaps>`{lang="html"}](/scripts/google-maps){lang="html"} component emits a single `ready` event when Google Maps loads.
30-
31-
The `ready` event payload contains:
32-
33-
| Property | Type | Description |
34-
|---|---|---|
35-
| `googleMaps` | `Ref<typeof google.maps>`{lang="html"} | The Google Maps API namespace |
36-
| `map` | `ShallowRef<google.maps.Map>`{lang="html"} | The map instance |
37-
| `createAdvancedMapMarker` | `(options?) => Promise<AdvancedMarkerElement>`{lang="html"} | Create a marker programmatically |
38-
| `resolveQueryToLatLng` | `(query: string) => Promise<LatLng>`{lang="html"} | Geocode a location string |
39-
| `importLibrary` | `(key: string) => Promise<any>`{lang="html"} | Load an additional Google Maps library |
40-
4118
To subscribe to Google Map events, you can use the `ready` event.
4219

4320
```vue

src/runtime/composables/useScript.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { resolveTrigger } from '#build/nuxt-scripts-trigger-resolver'
55
import { useScript as _useScript } from '@unhead/vue/scripts'
66
import { defu } from 'defu'
77
import { injectHead, onNuxtReady, useHead, useNuxtApp, useRuntimeConfig } from 'nuxt/app'
8-
import { ref } from 'vue'
8+
import { markRaw, ref } from 'vue'
99
import { logger } from '../logger'
1010

1111
type NuxtScriptsApp = ReturnType<typeof useNuxtApp> & {
@@ -199,5 +199,10 @@ export function useScript<T extends Record<symbol | string, any> = Record<symbol
199199
syncScripts()
200200
}
201201
}
202+
// Prevent Vue from making the instance deeply reactive, and guard against
203+
// circular JSON errors if anything calls JSON.stringify on it (Vue 3.5+
204+
// refs have circular `.dep` properties).
205+
markRaw(instance as any)
206+
;(instance as any).toJSON = () => ({ id: instance.id, status: instance.status.value })
202207
return instance as any as UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>
203208
}

0 commit comments

Comments
 (0)