@@ -44,7 +44,12 @@ await Task.WhenAll(serversToDispose.Select(async server =>
44
44
} ) ) ;
45
45
}
46
46
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 (
48
53
ProjectGraphNode projectNode ,
49
54
ProcessSpec processSpec ,
50
55
EnvironmentVariablesBuilder environmentBuilder ,
@@ -64,12 +69,9 @@ await Task.WhenAll(serversToDispose.Select(async server =>
64
69
}
65
70
}
66
71
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 ) ;
73
75
74
76
if ( server == null )
75
77
{
@@ -81,14 +83,10 @@ await Task.WhenAll(serversToDispose.Select(async server =>
81
83
{
82
84
// Start the server we just created:
83
85
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 ) ;
90
86
}
91
87
88
+ server . SetEnvironmentVariables ( environmentBuilder ) ;
89
+
92
90
return server ;
93
91
}
94
92
@@ -137,10 +135,10 @@ void handler(OutputLine line)
137
135
138
136
matchFound = true ;
139
137
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 ) )
142
140
{
143
- // first iteration:
141
+ // first build iteration of a root project :
144
142
LaunchBrowser ( launchProfile , match . Groups [ "url" ] . Value , server ) ;
145
143
}
146
144
else if ( server != null )
0 commit comments