@@ -48,7 +48,12 @@ await Task.WhenAll(serversToDispose.Select(async server =>
48
48
} ) ) ;
49
49
}
50
50
51
- public async ValueTask < BrowserRefreshServer ? > LaunchOrRefreshBrowserAsync (
51
+ /// <summary>
52
+ /// A single browser refresh server is created for each project that supports browser launching.
53
+ /// When the project is rebuilt we reuse the same refresh server and browser instance.
54
+ /// Reload message is sent to the browser in that case.
55
+ /// </summary>
56
+ public async ValueTask < BrowserRefreshServer ? > GetOrCreateBrowserRefreshServerAsync (
52
57
ProjectGraphNode projectNode ,
53
58
ProcessSpec processSpec ,
54
59
EnvironmentVariablesBuilder environmentBuilder ,
@@ -68,12 +73,9 @@ await Task.WhenAll(serversToDispose.Select(async server =>
68
73
}
69
74
}
70
75
71
- // Attach trigger to the process that launches browser on URL found in the process output.
72
- // Only do so for root projects, not for child processes.
73
- if ( projectOptions . IsRootProject )
74
- {
75
- processSpec . OnOutput += GetBrowserLaunchTrigger ( projectNode , projectOptions , server , cancellationToken ) ;
76
- }
76
+ // Attach trigger to the process that detects when the web server reports to the output that it's listening.
77
+ // Launches browser on the URL found in the process output for root projects.
78
+ processSpec . OnOutput += GetBrowserLaunchTrigger ( projectNode , projectOptions , server , cancellationToken ) ;
77
79
78
80
if ( server == null )
79
81
{
@@ -85,14 +87,10 @@ await Task.WhenAll(serversToDispose.Select(async server =>
85
87
{
86
88
// Start the server we just created:
87
89
await server . StartAsync ( cancellationToken ) ;
88
- server . SetEnvironmentVariables ( environmentBuilder ) ;
89
- }
90
- else
91
- {
92
- // Notify the browser of a project rebuild (delta applier notifies of updates):
93
- await server . SendWaitMessageAsync ( cancellationToken ) ;
94
90
}
95
91
92
+ server . SetEnvironmentVariables ( environmentBuilder ) ;
93
+
96
94
return server ;
97
95
}
98
96
@@ -145,10 +143,10 @@ void handler(OutputLine line)
145
143
146
144
matchFound = true ;
147
145
148
- var projectAddedToAttemptedSet = ImmutableInterlocked . Update ( ref _browserLaunchAttempted , static ( set , projectNode ) => set . Add ( projectNode ) , projectNode ) ;
149
- if ( projectAddedToAttemptedSet )
146
+ if ( projectOptions . IsRootProject &&
147
+ ImmutableInterlocked . Update ( ref _browserLaunchAttempted , static ( set , projectNode ) => set . Add ( projectNode ) , projectNode ) )
150
148
{
151
- // first iteration:
149
+ // first build iteration of a root project :
152
150
var launchUrl = GetLaunchUrl ( launchProfile . LaunchUrl , match . Groups [ "url" ] . Value ) ;
153
151
LaunchBrowser ( launchUrl , server ) ;
154
152
}
0 commit comments