@@ -44,7 +44,12 @@ await Task.WhenAll(serversToDispose.Select(async server =>
4444 } ) ) ;
4545 }
4646
47- public async ValueTask < BrowserRefreshServer ? > LaunchOrRefreshBrowserAsync (
47+ /// <summary>
48+ /// A single browser refresh server is created for each project that supports browser launching.
49+ /// When the project is rebuilt we reuse the same refresh server and browser instance.
50+ /// Reload message is sent to the browser in that case.
51+ /// </summary>
52+ public async ValueTask < BrowserRefreshServer ? > GetOrCreateBrowserRefreshServerAsync (
4853 ProjectGraphNode projectNode ,
4954 ProcessSpec processSpec ,
5055 EnvironmentVariablesBuilder environmentBuilder ,
@@ -64,12 +69,9 @@ await Task.WhenAll(serversToDispose.Select(async server =>
6469 }
6570 }
6671
67- // Attach trigger to the process that launches browser on URL found in the process output.
68- // Only do so for root projects, not for child processes.
69- if ( projectOptions . IsRootProject )
70- {
71- processSpec . OnOutput += GetBrowserLaunchTrigger ( projectNode , projectOptions , server , cancellationToken ) ;
72- }
72+ // Attach trigger to the process that detects when the web server reports to the output that it's listening.
73+ // Launches browser on the URL found in the process output for root projects.
74+ processSpec . OnOutput += GetBrowserLaunchTrigger ( projectNode , projectOptions , server , cancellationToken ) ;
7375
7476 if ( server == null )
7577 {
@@ -81,14 +83,10 @@ await Task.WhenAll(serversToDispose.Select(async server =>
8183 {
8284 // Start the server we just created:
8385 await server . StartAsync ( cancellationToken ) ;
84- server . SetEnvironmentVariables ( environmentBuilder ) ;
85- }
86- else
87- {
88- // Notify the browser of a project rebuild (delta applier notifies of updates):
89- await server . SendWaitMessageAsync ( cancellationToken ) ;
9086 }
9187
88+ server . SetEnvironmentVariables ( environmentBuilder ) ;
89+
9290 return server ;
9391 }
9492
@@ -137,10 +135,10 @@ void handler(OutputLine line)
137135
138136 matchFound = true ;
139137
140- var projectAddedToAttemptedSet = ImmutableInterlocked . Update ( ref _browserLaunchAttempted , static ( set , projectNode ) => set . Add ( projectNode ) , projectNode ) ;
141- if ( projectAddedToAttemptedSet )
138+ if ( projectOptions . IsRootProject &&
139+ ImmutableInterlocked . Update ( ref _browserLaunchAttempted , static ( set , projectNode ) => set . Add ( projectNode ) , projectNode ) )
142140 {
143- // first iteration:
141+ // first build iteration of a root project :
144142 LaunchBrowser ( launchProfile , match . Groups [ "url" ] . Value , server ) ;
145143 }
146144 else if ( server != null )
0 commit comments