Skip to content

Commit f32eca6

Browse files
authored
Merge branch 'release/9.0.2xx' into AspireBrowserLaunch
2 parents 8a8df71 + 4f810fb commit f32eca6

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/BuiltInTools/dotnet-watch/Browser/BrowserConnector.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ await Task.WhenAll(serversToDispose.Select(async server =>
4848
}));
4949
}
5050

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(
5257
ProjectGraphNode projectNode,
5358
ProcessSpec processSpec,
5459
EnvironmentVariablesBuilder environmentBuilder,
@@ -68,12 +73,9 @@ await Task.WhenAll(serversToDispose.Select(async server =>
6873
}
6974
}
7075

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);
7779

7880
if (server == null)
7981
{
@@ -85,14 +87,10 @@ await Task.WhenAll(serversToDispose.Select(async server =>
8587
{
8688
// Start the server we just created:
8789
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);
9490
}
9591

92+
server.SetEnvironmentVariables(environmentBuilder);
93+
9694
return server;
9795
}
9896

@@ -145,10 +143,10 @@ void handler(OutputLine line)
145143

146144
matchFound = true;
147145

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))
150148
{
151-
// first iteration:
149+
// first build iteration of a root project:
152150
var launchUrl = GetLaunchUrl(launchProfile.LaunchUrl, match.Groups["url"].Value);
153151
LaunchBrowser(launchUrl, server);
154152
}

src/BuiltInTools/dotnet-watch/DotNetWatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public override async Task WatchAsync(CancellationToken shutdownCancellationToke
6262
};
6363

6464
var browserRefreshServer = (projectRootNode != null)
65-
? await browserConnector.LaunchOrRefreshBrowserAsync(projectRootNode, processSpec, environmentBuilder, Context.RootProjectOptions, shutdownCancellationToken)
65+
? await browserConnector.GetOrCreateBrowserRefreshServerAsync(projectRootNode, processSpec, environmentBuilder, Context.RootProjectOptions, shutdownCancellationToken)
6666
: null;
6767

6868
environmentBuilder.SetProcessEnvironmentVariables(processSpec);

src/BuiltInTools/dotnet-watch/HotReload/ProjectLauncher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public EnvironmentOptions EnvironmentOptions
9494
}
9595
}
9696

97-
var browserRefreshServer = await browserConnector.LaunchOrRefreshBrowserAsync(projectNode, processSpec, environmentBuilder, projectOptions, cancellationToken);
97+
var browserRefreshServer = await browserConnector.GetOrCreateBrowserRefreshServerAsync(projectNode, processSpec, environmentBuilder, projectOptions, cancellationToken);
9898

9999
var arguments = new List<string>()
100100
{

0 commit comments

Comments
 (0)