Skip to content

Commit

Permalink
Stop copying content stream in .NET MAUI Blazor Windows
Browse files Browse the repository at this point in the history
Fixes: #9206

microsoft/CsWinRT#670 and https://task.ms/31565319 have been marked as resolved. This PR removes the existing logic which copies the content into a memory stream, and replaces it with a call to `AsRandomAccessStream()` (`IRandomAccessStream` is still required per the `CoreWebView2` API).

I tried out CSS hot reload with this change and things are working as expected. Not sure if there's a particular behavior/technique we can use to verify the validity of this change. Spoke with @Eilon regarding this, and per his recollection things were immediately hanging, and that's why this change was necessitated.
  • Loading branch information
TanayParikh committed Aug 8, 2022
1 parent d94a1ad commit f0114eb
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/BlazorWebView/src/Maui/Windows/WinUIWebViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@ protected override async Task HandleWebResourceRequest(CoreWebView2WebResourceRe
if (TryGetResponseContent(requestUri, allowFallbackOnHostPage, out var statusCode, out var statusMessage, out var content, out var headers)
&& statusCode != 404)
{
// NOTE: This is stream copying is to work around a hanging bug in WinRT with managed streams.
// See issue https://github.com/microsoft/CsWinRT/issues/670
var memStream = new MemoryStream();
content.CopyTo(memStream);
var ms = new InMemoryRandomAccessStream();
await ms.WriteAsync(memStream.GetWindowsRuntimeBuffer());

var headerString = GetHeaderString(headers);
eventArgs.Response = _coreWebView2Environment!.CreateWebResourceResponse(ms, statusCode, statusMessage, headerString);
eventArgs.Response = _coreWebView2Environment!.CreateWebResourceResponse(content.AsRandomAccessStream(), statusCode, statusMessage, headerString);
}
else if (new Uri(requestUri) is Uri uri && AppOriginUri.IsBaseOf(uri))
{
Expand Down

0 comments on commit f0114eb

Please sign in to comment.