nuxtseo-layer-devtools 0.3.6 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import type { NuxtDevtoolsClient } from '@nuxt/devtools-kit/types'
2
2
  import type { $Fetch } from 'nitropack/types'
3
3
  import type { Ref } from 'vue'
4
- import { onDevtoolsClientConnected } from '@nuxt/devtools-kit/iframe-client'
4
+ import { onDevtoolsClientConnected, useDevtoolsClient } from '@nuxt/devtools-kit/iframe-client'
5
5
  import { ofetch } from 'ofetch'
6
6
  import { ref, watch, watchEffect } from 'vue'
7
7
  import { isConnected, refreshSources, standaloneUrl } from './state'
@@ -24,13 +24,19 @@ export interface DevtoolsConnectionOptions {
24
24
  * - **Standalone**: running directly in a browser tab with a manual dev server URL
25
25
  */
26
26
  export function useDevtoolsConnection(options: DevtoolsConnectionOptions = {}): void {
27
+ // Workaround: devtools-kit@4.0.0-alpha.3 bug where onDevtoolsClientConnected
28
+ // defines a window.__NUXT_DEVTOOLS__ getter that reads clientRef.value, but
29
+ // clientRef is only initialized by useDevtoolsClient(). Call it first to avoid
30
+ // "Cannot read properties of undefined (reading 'value')" on the getter.
31
+ useDevtoolsClient()
32
+
27
33
  // Embedded mode: connect via devtools-kit iframe client
28
34
  onDevtoolsClientConnected(async (client) => {
29
35
  isConnected.value = true
30
36
  // @ts-expect-error untyped
31
- appFetch.value = client.host.app.$fetch
37
+ appFetch.value = client.host?.app?.$fetch
32
38
  watchEffect(() => {
33
- colorMode.value = client.host.app.colorMode?.value ?? (
39
+ colorMode.value = client.host?.app?.colorMode?.value ?? (
34
40
  window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
35
41
  )
36
42
  })
@@ -38,14 +44,18 @@ export function useDevtoolsConnection(options: DevtoolsConnectionOptions = {}):
38
44
  options.onConnected?.(client)
39
45
 
40
46
  if (options.onRouteChange) {
41
- const $route = client.host.nuxt.vueApp.config.globalProperties?.$route
42
- options.onRouteChange($route)
43
- const removeAfterEach = client.host.nuxt.$router.afterEach((route: any) => {
44
- options.onRouteChange!(route)
45
- })
46
- // Clean up when devtools client disconnects
47
- // @ts-expect-error app:unmount exists at runtime but is not in RuntimeNuxtHooks
48
- client.host.nuxt.hook('app:unmount', removeAfterEach)
47
+ const $route = client.host?.nuxt?.vueApp?.config?.globalProperties?.$route
48
+ if ($route)
49
+ options.onRouteChange($route)
50
+ const $router = client.host?.nuxt?.$router
51
+ if ($router) {
52
+ const removeAfterEach = $router.afterEach((route: any) => {
53
+ options.onRouteChange!(route)
54
+ })
55
+ // Clean up when devtools client disconnects
56
+ // @ts-expect-error app:unmount exists at runtime but is not in RuntimeNuxtHooks
57
+ client.host.nuxt.hook('app:unmount', removeAfterEach)
58
+ }
49
59
  }
50
60
  })
51
61
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxtseo-layer-devtools",
3
3
  "type": "module",
4
- "version": "0.3.6",
4
+ "version": "0.3.8",
5
5
  "description": "Shared Nuxt layer for Nuxt SEO devtools clients.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -8,8 +8,8 @@ export default defineNuxtPlugin(() => {
8
8
 
9
9
  useDevtoolsConnection({
10
10
  onConnected(client) {
11
- const props = client.host.nuxt.vueApp.config.globalProperties
12
- base.value = props?.$router?.options?.history?.base || client.host.app.baseURL || '/'
11
+ const props = client.host?.nuxt?.vueApp?.config?.globalProperties
12
+ base.value = props?.$router?.options?.history?.base || client.host?.app?.baseURL || '/'
13
13
  const $route = props?.$route
14
14
  if ($route) {
15
15
  path.value = $route.path || '/'