[Windows] Blazor Hybrid flickers on launch (white, then gray background)
Description
When Blazor Hybrid app is launched on Windows, MAUI displays two additional screens before showing Blazor content:
- White blank screen
- Gray blank screen
- Only now Blazor content is displayed
All happens in a fraction of a second causing effect of flickering. Is there any way to eliminate this effect, or at least set some fixed background color to first two screens?
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
8.0.5
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows
Did you find any workaround?
No response
Relevant log output
No response
Verified this on 8.0.6. Repro on Windows 11 with .NET MAUI Blazor Hybird App template: MauiApp9.zip
Hi, what I saw when starting MAUI Blazor Hybrid template app is that the first blank window is outside of the second one (which is app), it opens and closes quickly. I believe every BlazorWebView and/or WebView initialization causes that "effect", but I am not sure.
Startup sequence
First blank window:
Second window is actually app itself. Sometimes, shortly, both windows are on the screen together.
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.91" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>
OS: Windows 10 & Windows 11
This flashing window at startup seems new to me. I have observed this just for a couple of days, and I work with Blazor Hybrid everyday (it is my job). Is there any workaround?
The problem has gone (for my .NET MAUI Blazor Hybrid App) after updating .NET 8.0.400 to the current version .NET 8.0.402
Hi, if u need a work around, u can first set the blazorwebview visibilty to false and wait for like 2.5 secs or so and then make it visible. but its a hard coded delay it will still flash on slower devices. like so
private void MainPage_Loaded(object? sender, EventArgs e)
{
Task.Delay(2500).ContinueWith(_ =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
blazorWebView.IsVisible = true;
});
});
WebviewInstance = blazorWebView;
}
or A better solution 😊
<BlazorWebView
x:Name="blazorWebView"
Background="#333333"
HostPage="wwwroot/index.html"
IsVisible="False">
<BlazorWebView.RootComponents>
<RootComponent ComponentType="{x:Type components:Routes}" Selector="#app" />
</BlazorWebView.RootComponents>
</BlazorWebView>
public partial class MainPage : ContentView
{
public static BlazorWebView? WebviewInstance { get; set; }
public MainPage()
{
InitializeComponent();
this.Loaded += MainPage_Loaded;
}
private void MainPage_Loaded(object? sender, EventArgs e)
{
WebviewInstance = blazorWebView;
}
[JSInvokable]
public static void ShowBlazorWebView()
{
MainThread.BeginInvokeOnMainThread(() =>
{
WebviewInstance!.IsVisible = true;
});
}
}
and then in index.html
<script>
function notifyBlazorReady() {
DotNet.invokeMethodAsync('YourAppName', 'ShowBlazorWebView');
}
</script>
change YourAppName and finally in MainLayout
@inject IJSRuntime JSRuntime
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
JSRuntime.InvokeVoidAsync("notifyBlazorReady");
}
}
hope this helps ..!!!
https://github.com/dotnet/maui/issues/19942#issuecomment-2387762152