Skip to content

Commit cfa34cb

Browse files
committed
Assume basline capabilities (#23185)
In a Blazor app, the apply-update capabilities are available after the app is up and running in the browser. Occasionally it takes long for the app to start up and our baseline task times out. Currently we return an empty list of capabilities which causes the compiler to produce no deltas. This PR bumps up the timeout ever so slightly and returns baseline capabilities instead. Fixes dotnet/aspnetcore#36723
1 parent b8b6c7a commit cfa34cb

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
using System.Linq;
1111
using System.Net.WebSockets;
1212
using System.Text;
13-
using System.Text.Json;
1413
using System.Threading;
1514
using System.Threading.Tasks;
1615
using Microsoft.CodeAnalysis.ExternalAccess.Watch.Api;
17-
using Microsoft.Extensions.HotReload;
1816
using Microsoft.Extensions.Tools.Internal;
1917

2018
namespace Microsoft.DotNet.Watcher.Tools
2119
{
2220
internal class BlazorWebAssemblyDeltaApplier : IDeltaApplier
2321
{
2422
private static Task<ImmutableArray<string>>? _cachedCapabilties;
23+
private static readonly ImmutableArray<string> _baselineCapabilities = ImmutableArray.Create<string>("Baseline");
2524
private readonly IReporter _reporter;
2625
private int _sequenceId;
2726

@@ -48,7 +47,7 @@ async Task<ImmutableArray<string>> GetApplyUpdateCapabilitiesCoreAsync()
4847
{
4948
if (context.BrowserRefreshServer is null)
5049
{
51-
return ImmutableArray<string>.Empty;
50+
return _baselineCapabilities;
5251
}
5352

5453
await context.BrowserRefreshServer.WaitForClientConnectionAsync(cancellationToken);
@@ -58,14 +57,14 @@ async Task<ImmutableArray<string>> GetApplyUpdateCapabilitiesCoreAsync()
5857
var buffer = ArrayPool<byte>.Shared.Rent(32 * 1024);
5958
try
6059
{
61-
// We'll query the browser and ask it send capabilities. If the browser does not respond in 10s, we'll assume something is amiss and return
62-
// no capabilities. This should give you baseline hot reload capabilties.
60+
// We'll query the browser and ask it send capabilities. If the browser does not respond in a short duration, we'll assume something is amiss and return
61+
// baseline capabilities.
6362
var response = await context.BrowserRefreshServer.ReceiveAsync(buffer, cancellationToken)
6463
.AsTask()
65-
.WaitAsync(TimeSpan.FromSeconds(10), cancellationToken);
64+
.WaitAsync(TimeSpan.FromSeconds(15), cancellationToken);
6665
if (!response.HasValue || !response.Value.EndOfMessage || response.Value.MessageType != WebSocketMessageType.Text)
6766
{
68-
return ImmutableArray<string>.Empty;
67+
return _baselineCapabilities;
6968
}
7069

7170
var values = Encoding.UTF8.GetString(buffer.AsSpan(0, response.Value.Count));
@@ -83,7 +82,7 @@ async Task<ImmutableArray<string>> GetApplyUpdateCapabilitiesCoreAsync()
8382
ArrayPool<byte>.Shared.Return(buffer);
8483
}
8584

86-
return ImmutableArray<string>.Empty;
85+
return _baselineCapabilities;
8786
}
8887
}
8988

0 commit comments

Comments
 (0)