From 6dece813047c52d7351d3a5b0b398d8e9296f815 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 27 Dec 2021 15:34:58 -0800 Subject: [PATCH] Assume basline capabilities 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 https://github.com/dotnet/aspnetcore/issues/36723 --- .../HotReload/BlazorWebAssemblyDeltaApplier.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/BuiltInTools/dotnet-watch/HotReload/BlazorWebAssemblyDeltaApplier.cs b/src/BuiltInTools/dotnet-watch/HotReload/BlazorWebAssemblyDeltaApplier.cs index 54aac04ef06f..c65ab9789b2e 100644 --- a/src/BuiltInTools/dotnet-watch/HotReload/BlazorWebAssemblyDeltaApplier.cs +++ b/src/BuiltInTools/dotnet-watch/HotReload/BlazorWebAssemblyDeltaApplier.cs @@ -10,11 +10,9 @@ using System.Linq; using System.Net.WebSockets; using System.Text; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.ExternalAccess.Watch.Api; -using Microsoft.Extensions.HotReload; using Microsoft.Extensions.Tools.Internal; namespace Microsoft.DotNet.Watcher.Tools @@ -22,6 +20,7 @@ namespace Microsoft.DotNet.Watcher.Tools internal class BlazorWebAssemblyDeltaApplier : IDeltaApplier { private static Task>? _cachedCapabilties; + private static readonly ImmutableArray _baselineCapabilities = ImmutableArray.Create("Baseline"); private readonly IReporter _reporter; private int _sequenceId; @@ -48,7 +47,7 @@ async Task> GetApplyUpdateCapabilitiesCoreAsync() { if (context.BrowserRefreshServer is null) { - return ImmutableArray.Empty; + return _baselineCapabilities; } await context.BrowserRefreshServer.WaitForClientConnectionAsync(cancellationToken); @@ -58,14 +57,14 @@ async Task> GetApplyUpdateCapabilitiesCoreAsync() var buffer = ArrayPool.Shared.Rent(32 * 1024); try { - // 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 - // no capabilities. This should give you baseline hot reload capabilties. + // 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 + // baseline capabilities. var response = await context.BrowserRefreshServer.ReceiveAsync(buffer, cancellationToken) .AsTask() - .WaitAsync(TimeSpan.FromSeconds(10), cancellationToken); + .WaitAsync(TimeSpan.FromSeconds(15), cancellationToken); if (!response.HasValue || !response.Value.EndOfMessage || response.Value.MessageType != WebSocketMessageType.Text) { - return ImmutableArray.Empty; + return _baselineCapabilities; } var values = Encoding.UTF8.GetString(buffer.AsSpan(0, response.Value.Count)); @@ -83,7 +82,7 @@ async Task> GetApplyUpdateCapabilitiesCoreAsync() ArrayPool.Shared.Return(buffer); } - return ImmutableArray.Empty; + return _baselineCapabilities; } }