Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
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
{
internal class BlazorWebAssemblyDeltaApplier : IDeltaApplier
{
private static Task<ImmutableArray<string>>? _cachedCapabilties;
private static readonly ImmutableArray<string> _baselineCapabilities = ImmutableArray.Create<string>("Baseline");
private readonly IReporter _reporter;
private int _sequenceId;

Expand All @@ -48,7 +47,7 @@ async Task<ImmutableArray<string>> GetApplyUpdateCapabilitiesCoreAsync()
{
if (context.BrowserRefreshServer is null)
{
return ImmutableArray<string>.Empty;
return _baselineCapabilities;
}

await context.BrowserRefreshServer.WaitForClientConnectionAsync(cancellationToken);
Expand All @@ -58,14 +57,14 @@ async Task<ImmutableArray<string>> GetApplyUpdateCapabilitiesCoreAsync()
var buffer = ArrayPool<byte>.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<string>.Empty;
return _baselineCapabilities;
}

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

return ImmutableArray<string>.Empty;
return _baselineCapabilities;
}
}

Expand Down