@@ -57,12 +57,16 @@ import {serializeDirectiveState} from './state-serializer/state-serializer';
57
57
import { runOutsideAngular , unwrapSignal } from './utils' ;
58
58
import { DirectiveForestHooks } from './hooks/hooks' ;
59
59
60
+ type InspectorRef = { ref : ComponentInspector | null } ;
61
+
60
62
export const subscribeToClientEvents = (
61
63
messageBus : MessageBus < Events > ,
62
64
depsForTestOnly ?: {
63
65
directiveForestHooks ?: typeof DirectiveForestHooks ;
64
66
} ,
65
67
) : void => {
68
+ const inspector : InspectorRef = { ref : null } ;
69
+
66
70
messageBus . on ( 'shutdown' , shutdownCallback ( messageBus ) ) ;
67
71
68
72
messageBus . on (
@@ -75,7 +79,7 @@ export const subscribeToClientEvents = (
75
79
messageBus . on ( 'startProfiling' , startProfilingCallback ( messageBus ) ) ;
76
80
messageBus . on ( 'stopProfiling' , stopProfilingCallback ( messageBus ) ) ;
77
81
78
- messageBus . on ( 'setSelectedComponent' , selectedComponentCallback ) ;
82
+ messageBus . on ( 'setSelectedComponent' , selectedComponentCallback ( inspector ) ) ;
79
83
80
84
messageBus . on ( 'getNestedProperties' , getNestedPropertiesCallback ( messageBus ) ) ;
81
85
messageBus . on ( 'getRoutes' , getRoutesCallback ( messageBus ) ) ;
@@ -94,7 +98,8 @@ export const subscribeToClientEvents = (
94
98
} ) ;
95
99
96
100
if ( appIsAngularInDevMode ( ) && appIsSupportedAngularVersion ( ) && appIsAngularIvy ( ) ) {
97
- setupInspector ( messageBus ) ;
101
+ inspector . ref = setupInspector ( messageBus ) ;
102
+
98
103
// Often websites have `scroll` event listener which triggers
99
104
// Angular's change detection. We don't want to constantly send
100
105
// update requests, instead we want to request an update at most
@@ -175,12 +180,13 @@ const stopProfilingCallback = (messageBus: MessageBus<Events>) => () => {
175
180
messageBus . emit ( 'profilerResults' , [ stopProfiling ( ) ] ) ;
176
181
} ;
177
182
178
- const selectedComponentCallback = ( position : ElementPosition ) => {
183
+ const selectedComponentCallback = ( inspector : InspectorRef ) => ( position : ElementPosition ) => {
179
184
const node = queryDirectiveForest (
180
185
position ,
181
186
initializeOrGetDirectiveForestHooks ( ) . getIndexedDirectiveForest ( ) ,
182
187
) ;
183
188
setConsoleReference ( { node, position} ) ;
189
+ inspector . ref ?. highlightByPosition ( position ) ;
184
190
} ;
185
191
186
192
const getNestedPropertiesCallback =
@@ -335,7 +341,7 @@ const checkForAngular = (messageBus: MessageBus<Events>): void => {
335
341
] ) ;
336
342
} ;
337
343
338
- const setupInspector = ( messageBus : MessageBus < Events > ) => {
344
+ const setupInspector = ( messageBus : MessageBus < Events > ) : ComponentInspector => {
339
345
const inspector = new ComponentInspector ( {
340
346
onComponentEnter : ( id : number ) => {
341
347
messageBus . emit ( 'highlightComponent' , [ id ] ) ;
@@ -358,6 +364,8 @@ const setupInspector = (messageBus: MessageBus<Events>) => {
358
364
359
365
messageBus . on ( 'createHydrationOverlay' , inspector . highlightHydrationNodes ) ;
360
366
messageBus . on ( 'removeHydrationOverlay' , inspector . removeHydrationHighlights ) ;
367
+
368
+ return inspector ;
361
369
} ;
362
370
363
371
export interface SerializableDirectiveInstanceType extends DirectiveType {
0 commit comments