-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blazor Hybrid CSS Hot Reload Fixes (#9645)
* Stop copying content stream in .NET MAUI Blazor Windows 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. * AutoCloseOnReadCompleteStream * Ensure old response content is closed out for hot reload * PR Feedback
- Loading branch information
1 parent
41b1c9e
commit ff3e934
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/BlazorWebView/src/SharedSource/AutoCloseOnReadCompleteStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#if WEBVIEW2_WINFORMS || WEBVIEW2_WPF | ||
|
||
using System.IO; | ||
|
||
namespace Microsoft.AspNetCore.Components.WebView.WebView2 | ||
{ | ||
internal class AutoCloseOnReadCompleteStream : Stream | ||
{ | ||
private readonly Stream _baseStream; | ||
|
||
public AutoCloseOnReadCompleteStream(Stream baseStream) | ||
{ | ||
_baseStream = baseStream; | ||
} | ||
|
||
public override bool CanRead => _baseStream.CanRead; | ||
|
||
public override bool CanSeek => _baseStream.CanSeek; | ||
|
||
public override bool CanWrite => _baseStream.CanWrite; | ||
|
||
public override long Length => _baseStream.Length; | ||
|
||
public override long Position { get => _baseStream.Position; set => _baseStream.Position = value; } | ||
|
||
public override void Flush() => _baseStream.Flush(); | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
var bytesRead = _baseStream.Read(buffer, offset, count); | ||
|
||
// Stream.Read only returns 0 when it has reached the end of stream | ||
// and no further bytes are expected. Otherwise it blocks until | ||
// one or more (and at most count) bytes can be read. | ||
if (bytesRead == 0) | ||
{ | ||
_baseStream.Close(); | ||
} | ||
|
||
return bytesRead; | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) => _baseStream.Seek(offset, origin); | ||
|
||
public override void SetLength(long value) => _baseStream.SetLength(value); | ||
|
||
public override void Write(byte[] buffer, int offset, int count) => _baseStream.Write(buffer, offset, count); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters