@@ -57,12 +57,16 @@ import {serializeDirectiveState} from './state-serializer/state-serializer';
5757import { runOutsideAngular , unwrapSignal } from './utils' ;
5858import { DirectiveForestHooks } from './hooks/hooks' ;
5959
60+ type InspectorRef = { ref : ComponentInspector | null } ;
61+
6062export const subscribeToClientEvents = (
6163 messageBus : MessageBus < Events > ,
6264 depsForTestOnly ?: {
6365 directiveForestHooks ?: typeof DirectiveForestHooks ;
6466 } ,
6567) : void => {
68+ const inspector : InspectorRef = { ref : null } ;
69+
6670 messageBus . on ( 'shutdown' , shutdownCallback ( messageBus ) ) ;
6771
6872 messageBus . on (
@@ -75,7 +79,7 @@ export const subscribeToClientEvents = (
7579 messageBus . on ( 'startProfiling' , startProfilingCallback ( messageBus ) ) ;
7680 messageBus . on ( 'stopProfiling' , stopProfilingCallback ( messageBus ) ) ;
7781
78- messageBus . on ( 'setSelectedComponent' , selectedComponentCallback ) ;
82+ messageBus . on ( 'setSelectedComponent' , selectedComponentCallback ( inspector ) ) ;
7983
8084 messageBus . on ( 'getNestedProperties' , getNestedPropertiesCallback ( messageBus ) ) ;
8185 messageBus . on ( 'getRoutes' , getRoutesCallback ( messageBus ) ) ;
@@ -94,7 +98,8 @@ export const subscribeToClientEvents = (
9498 } ) ;
9599
96100 if ( appIsAngularInDevMode ( ) && appIsSupportedAngularVersion ( ) && appIsAngularIvy ( ) ) {
97- setupInspector ( messageBus ) ;
101+ inspector . ref = setupInspector ( messageBus ) ;
102+
98103 // Often websites have `scroll` event listener which triggers
99104 // Angular's change detection. We don't want to constantly send
100105 // update requests, instead we want to request an update at most
@@ -175,12 +180,13 @@ const stopProfilingCallback = (messageBus: MessageBus<Events>) => () => {
175180 messageBus . emit ( 'profilerResults' , [ stopProfiling ( ) ] ) ;
176181} ;
177182
178- const selectedComponentCallback = ( position : ElementPosition ) => {
183+ const selectedComponentCallback = ( inspector : InspectorRef ) => ( position : ElementPosition ) => {
179184 const node = queryDirectiveForest (
180185 position ,
181186 initializeOrGetDirectiveForestHooks ( ) . getIndexedDirectiveForest ( ) ,
182187 ) ;
183188 setConsoleReference ( { node, position} ) ;
189+ inspector . ref ?. highlightByPosition ( position ) ;
184190} ;
185191
186192const getNestedPropertiesCallback =
@@ -335,7 +341,7 @@ const checkForAngular = (messageBus: MessageBus<Events>): void => {
335341 ] ) ;
336342} ;
337343
338- const setupInspector = ( messageBus : MessageBus < Events > ) => {
344+ const setupInspector = ( messageBus : MessageBus < Events > ) : ComponentInspector => {
339345 const inspector = new ComponentInspector ( {
340346 onComponentEnter : ( id : number ) => {
341347 messageBus . emit ( 'highlightComponent' , [ id ] ) ;
@@ -358,6 +364,8 @@ const setupInspector = (messageBus: MessageBus<Events>) => {
358364
359365 messageBus . on ( 'createHydrationOverlay' , inspector . highlightHydrationNodes ) ;
360366 messageBus . on ( 'removeHydrationOverlay' , inspector . removeHydrationHighlights ) ;
367+
368+ return inspector ;
361369} ;
362370
363371export interface SerializableDirectiveInstanceType extends DirectiveType {
0 commit comments