1+ import type { NuxtDevtoolsHostClient } from '@nuxt/devtools-kit/types'
12import { defineNuxtPlugin , useRouter } from '#imports'
23import { triggerRef } from 'vue'
34import { useClient } from '../composables/client'
@@ -16,27 +17,47 @@ export default defineNuxtPlugin(() => {
1617 rpc . openInEditor ( path )
1718 }
1819
19- Object . defineProperty ( window , '__NUXT_DEVTOOLS_VIEW__' , {
20- value : {
21- setClient ( _client ) {
22- if ( client . value === _client )
23- return
20+ function setupClient ( _client : NuxtDevtoolsHostClient ) {
21+ if ( client . value === _client )
22+ return
23+
24+ client . value = _client
25+
26+ _client . hooks . hook ( 'host:update:reactivity' , onUpdateReactivity )
27+ _client . hooks . hook ( 'host:inspector:click' , onInspectorClick )
28+ _client . hooks . hook ( 'host:action:reload' , ( ) => location . reload ( ) )
29+ _client . hooks . hook ( 'host:action:navigate' , ( path : string ) => router . push ( path ) )
2430
25- client . value = _client
31+ // eslint-disable-next-line no-console
32+ console . log ( '[nuxt-devtools] Client connected' , _client )
33+ }
2634
27- _client . hooks . hook ( 'host:update:reactivity' , onUpdateReactivity )
28- _client . hooks . hook ( 'host:inspector:click' , onInspectorClick )
29- _client . hooks . hook ( 'host:action:reload' , ( ) => location . reload ( ) )
30- _client . hooks . hook ( 'host:action:navigate' , ( path : string ) => router . push ( path ) )
35+ function connectParent ( ) {
36+ try {
37+ if ( window . parent === window )
38+ return
39+ if ( window . parent ?. __NUXT_DEVTOOLS_HOST__ ) {
40+ setupClient ( window . parent . __NUXT_DEVTOOLS_HOST__ )
41+ }
42+ }
43+ catch ( error ) {
44+ console . error ( '[nuxt-devtools] Failed to connect parent' , error )
45+ }
46+ }
3147
32- // eslint-disable-next-line no-console
33- console . log ( '[nuxt-devtools] Client connected' , _client )
48+ Object . defineProperty ( window , '__NUXT_DEVTOOLS_VIEW__' , {
49+ value : {
50+ setClient ( _client ) {
51+ setupClient ( _client )
3452 } ,
3553 } as typeof window [ '__NUXT_DEVTOOLS_VIEW__' ] ,
3654 enumerable : false ,
3755 configurable : true ,
3856 } )
3957
58+ connectParent ( )
59+ setTimeout ( ( ) => connectParent ( ) , 1000 )
60+
4061 router . afterEach ( ( ) => {
4162 const path = router . currentRoute . value ?. path
4263 if ( ! path || path . includes ( '__' ) )
0 commit comments