You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Blazor] Auto Render not working properly in .NET 8 and page locks until WebAssembly start #52154
area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-full-stack-web-uiFull stack web UI with Blazor
I updated Visual Studio to the latest version 17.8.0 and created a Blazor app using Auto render mode With Dotnet 8. When I run the application and navigate to the Counter tab, the whole page locks up until the WebAssembly Start. I can't do anything or switch to another tab until the download Finished And WebAssembly Start, even though it happens quickly locally. This could cause problems in production where the download may take longer. It also goes against the purpose of Auto render mode.
Expected Behavior
With auto render mode, the page should initially use server-side rendering. Once WebAssembly finishes downloading And Start, it can switch over seamlessly without locking up the page.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
NET 8 , Windows 10-64
Anything else?
As you can see, the page is locked and prevents navigating to another tab.
Reacted by Michael Brendle, Carl Franklin, Ziaul Hasan Hamim, ihorlazarenko, MrChriZ, arthastheking113, F. Donnet, JP, Diego Ribeiro, Mike Surcouf and 3 more
changed the title [-][Blazor] Auto Render not working properly in .NET 8 and page locks until WebAssembly downloads[/-][+][Blazor] Auto Render not working properly in .NET 8 and page locks until WebAssembly start[/+]on Nov 17, 2023
The delay is most likely due to starting up the .NET WebAssembly runtime, not the download. I believe the issue is we don't currently have a way to download the .NET WebAssembly runtime without also starting it, so this delay happens even on the first visit when using interactive server rendering. But even if we could avoid that delay on the first visit, on subsequent visits you'd still see the delay as the runtime starts up even though the runtime has been cached.
I found out that OnAfterRender actually can be an indicator that the framework and dependencies has been loaded. I think I'm going to have a root level component that will display a waiting indicator or something. My problem is that my clients will have a fast initial response from the server, but the overall hydration is taking a long time (especially on mobile end with slow connectivity)
In the end, my clients would be more confused when there's no interactivity yet established. My observation is that OnAfterRender gets executed when the framework has been loaded fully. Maybe we can get used to it.
Can you clarify what same thing you are seeing? The original report suggested that the UI is locked while downloading WebAssembly resources, but as far as we understand that is not the case.
If you mean that the UI is locked while the WebAssembly runtime starts (not while downloading, but after downloading), this is true and always has been since the beginning of Blazor WebAssembly. Over the years we've made it faster - it took about 1 second to start on the first version, and is down to about 350ms on recent hardware. Of course it could take longer on a low-end mobile device.
Update: I think I get what you mean now, which is that on the first visit for a given user, when it's using Server interactivity
because WebAssembly files aren't yet downloaded, there is a small pause (usually< 500ms, but depends on CPU speed) once the WebAssembly files finish downloading. Is that right?
If you change the Counter title to: <h1>Counter @(OperatingSystem.IsBrowser() ? "Wasm" : "Server")</h1> It's kinda neat to watch the change as it happens.
The switchover you'll be seeing here is between prerendered content (which will display "Server") and then live interactive content (which will display "Wasm" if the wasm resources are already downloaded and cached). What sort of delay are you seeing that is much longer than expected?
It seems this problem only happens in debug mode. What I mean is that it's more noticeable, not that there is no locking at all in other modes.
In debug mode with Visual Studio it takes around 6 seconds , with dotnet run it takes less than 1 sec or half sec, and in release you almost don't feel your page is locked.
It seems like we don't have any issues in production mode.
@SteveSandersonMS I am facing the same issue. In auto interactivity mode it is supposed to connect to the server with signalr instantly. But it doesn't do that rather it waits for the wasm runtime to be loaded and then connects to the server. It destroys the whole purpose of auto interactivity. The app doesn't become interactive before wasm runtime loads unlike server mode which starts instantaneously. In my case the browser first loads webassembly files and then it connects to the server with signalr. Shouldn't it first make a signalr connection and then load the files? In my network tab, I can clearly see that wasm files are downloaded before websocket connection.
Reacted by achmstein, Scott McLeod, setroy, Nathan Berkowitz, littlelioncjt, Kamys85, Kevin Gates and José Luis Chaudary
In my case the browser first loads webassembly files and then it connects to the server with signalr
@ziaulhasanhamim When you use the word "loads" here, do you mean "downloads" (as in the WebAssembly files are not already cached, and you are waiting for them to be transferred over the network), or do you mean it in the sense of "starts" (as in, the WebAssembly files are already downloaded, but it takes some nonzero time to start the .NET runtime under WebAssembly, most likely ~0.5s assuming you are not debugging).
@SteveSandersonMS I meant that it is not cached. When wasm runtime is not cached it first downloads the wasm files then connects to server through websockets. But if it has to download the wasm runtime first then what is the benefit of auto interactivity.
But the WebAssembly runtime doesn't actually start until all .wasm downloads have completed.
If the app is locking up, it's probably the WebAssembly runtime starting, not being downloaded. The WebAssembly runtime starts synchronously, which is why the webpage becomes temporarily non-interactive. Does the same thing happen when using an InteractiveWebAssembly render mode? If so, that would indicate that this is not a problem with the InteractiveAuto mode, but rather a performance characteristic of WebAssembly runtime startup.
I'm a bit lost on the order of things. I hadn't considered that the WebAssembly runtime starting could block the Blazor Server interactivity.
So if the app downloads quite quickly then the WebAssembly runtime starting can still block the Blazor Server interactivity giving the same feel that the app is not responding even though the websocket is open?
So if the app downloads quite quickly then the WebAssembly runtime starting can still block the Blazor Server interactivity giving the same feel that the app is not responding even though the websocket is open?
I should have been clearer - the WebAssembly runtime (as in the code from the .Client project) won't actually start until all .wasm downloads have completed and a component requires WebAssembly interactivity. So, if you had an InteractiveServer component and InteractiveWebAssembly component on the same page, the starting of the WebAssembly runtime could momentarily block interactivity for the InteractiveServer component. But this shouldn't happen when only using the InteractiveAuto render mode. If you do see a delay like that, it's probably because the InteractiveAuto component is using WebAssembly interactivity.
Thanks for the fix, @MackinnonBuck. I updated my SDK to 8.0.2 and tried on a new project and the issue looks fixed. However, I see that all the wasm files are downloaded serially (see image below). Is there a way to make this parallel (or, say 10 degrees of parallelism), while still having the websocket connection be established before the wasm is downloaded?
@saintarian you cannot download 10 files concurrently because your application will be unusable. Maybe it is not a problem on high speed fiber Internet connection but try to download a few files concurrently using cellular network and check latency with ping command.
It may be unrelated and specific to something I have done in my app but... Is anyone having difficulty with InteractiveAuto since the last update when using: @rendermode @(new InteractiveAutoRenderMode(prerender: false))
The page I am trying to render is injecting services from the WASM service collection which is why I am not pre-rendering.
Page loads no issues with @rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
But when using auto I get nothing loading and if I navigate to another page I get a circuit exception.
The component loads normally if I refresh the page once or twice. Maybe a BrowserLink / Debugging issue?
I did notice that after navigating to the page the DevTools Debugger does briefly hold on an unhandled exception but even with "Pause on uncaught exceptions" ticked it jumps over it so quickly I can't catch it.
Edit:
I was not trying to use prerender = false prior to the 8.0.2 update so I don't know if this is new behavior since the changes talked about above.
@bcookew If the page initially loads in server mode then it will be trying to resolve the injected dependencies from the server side service provider. The dependencies will need to be present there, if they're not that could explain the problems.
@bcookew If the page initially loads in server mode then it will be trying to resolve the injected dependencies from the server side service provider. The dependencies will need to be present there, if they're not that could explain the problems.
Good offer. That was, in truth, where I started my day. I had a look at the MS Docs related to render modes here. And followed their advice to set prerender to false. This did indeed clear the DI issue but left me with this odd behavior where the page never loads unless I refresh a couple of times.
Open to further thoughts / discussion on this for sure!
@bcookew It still sounds like a DI issue. Setting prerender to false will still mean it tries to load in server (SignalR) mode initially. Then when you refresh, if the wasm resources have been downloaded by that point then after refreshing it will switch to wasm mode.
So you still need to ensure the dependencies can be resolved server side, or change the render mode from Auto to WebAssembly.
I stumbled upon a similar problem. A browser which doesn't have WASM or WASM is disabled alltogether. I tested with Firefox setting javascript.options.wasm to false. I'd expect it to still work using server-side rendering. Instead, it seems like it crashes and no interactivity works.
area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-full-stack-web-uiFull stack web UI with Blazor
Activity
[-][Blazor] Auto Render not working properly in .NET 8 and page locks until WebAssembly downloads[/-][+][Blazor] Auto Render not working properly in .NET 8 and page locks until WebAssembly start[/+]danroth27 commentedon Nov 17, 2023
The delay is most likely due to starting up the .NET WebAssembly runtime, not the download. I believe the issue is we don't currently have a way to download the .NET WebAssembly runtime without also starting it, so this delay happens even on the first visit when using interactive server rendering. But even if we could avoid that delay on the first visit, on subsequent visits you'd still see the delay as the runtime starts up even though the runtime has been cached.
@lewing @MackinnonBuck
carlfranklin commentedon Nov 17, 2023
I’m seeing the same thing
ray440 commentedon Nov 17, 2023
If you change the Counter title to:
It's kinda neat to watch the change as it happens.
The delay is expected but much longer than expected leading to a stalled UX for antsy users.
Is there a way to tell what
@rendermodeis?danroth27 commentedon Nov 17, 2023
Not currently: #49401
carlfranklin commentedon Nov 17, 2023
mkalinski93 commentedon Nov 18, 2023
I found out that OnAfterRender actually can be an indicator that the framework and dependencies has been loaded. I think I'm going to have a root level component that will display a waiting indicator or something. My problem is that my clients will have a fast initial response from the server, but the overall hydration is taking a long time (especially on mobile end with slow connectivity)
In the end, my clients would be more confused when there's no interactivity yet established. My observation is that OnAfterRender gets executed when the framework has been loaded fully. Maybe we can get used to it.
SteveSandersonMS commentedon Nov 20, 2023
Can you clarify what same thing you are seeing? The original report suggested that the UI is locked while downloading WebAssembly resources, but as far as we understand that is not the case.
If you mean that the UI is locked while the WebAssembly runtime starts (not while downloading, but after downloading), this is true and always has been since the beginning of Blazor WebAssembly. Over the years we've made it faster - it took about 1 second to start on the first version, and is down to about 350ms on recent hardware. Of course it could take longer on a low-end mobile device.
Update: I think I get what you mean now, which is that on the first visit for a given user, when it's using Server interactivity
because WebAssembly files aren't yet downloaded, there is a small pause (usually< 500ms, but depends on CPU speed) once the WebAssembly files finish downloading. Is that right?
The switchover you'll be seeing here is between prerendered content (which will display "Server") and then live interactive content (which will display "Wasm" if the wasm resources are already downloaded and cached). What sort of delay are you seeing that is much longer than expected?
AmBplus commentedon Nov 20, 2023
It seems this problem only happens in debug mode. What I mean is that it's more noticeable, not that there is no locking at all in other modes.
In debug mode with Visual Studio it takes around 6 seconds , with dotnet run it takes less than 1 sec or half sec, and in release you almost don't feel your page is locked.
It seems like we don't have any issues in production mode.
carlfranklin commentedon Nov 20, 2023
ziaulhasanhamim commentedon Nov 22, 2023
@SteveSandersonMS I am facing the same issue. In auto interactivity mode it is supposed to connect to the server with signalr instantly. But it doesn't do that rather it waits for the wasm runtime to be loaded and then connects to the server. It destroys the whole purpose of auto interactivity. The app doesn't become interactive before wasm runtime loads unlike server mode which starts instantaneously. In my case the browser first loads webassembly files and then it connects to the server with signalr. Shouldn't it first make a signalr connection and then load the files? In my network tab, I can clearly see that wasm files are downloaded before websocket connection.
SteveSandersonMS commentedon Nov 22, 2023
@ziaulhasanhamim When you use the word "loads" here, do you mean "downloads" (as in the WebAssembly files are not already cached, and you are waiting for them to be transferred over the network), or do you mean it in the sense of "starts" (as in, the WebAssembly files are already downloaded, but it takes some nonzero time to start the .NET runtime under WebAssembly, most likely ~0.5s assuming you are not debugging).
ziaulhasanhamim commentedon Nov 22, 2023
@SteveSandersonMS I meant that it is not cached. When wasm runtime is not cached it first downloads the wasm files then connects to server through websockets. But if it has to download the wasm runtime first then what is the benefit of auto interactivity.
AmBplus commentedon Nov 22, 2023
@ziaulhasanhamim , Try Publish And See Still Have Delay
62 remaining items
mikes-gh commentedon Feb 15, 2024
@MackinnonBuck
I'm a bit lost on the order of things. I hadn't considered that the WebAssembly runtime starting could block the Blazor Server interactivity.
So if the app downloads quite quickly then the WebAssembly runtime starting can still block the Blazor Server interactivity giving the same feel that the app is not responding even though the websocket is open?
MackinnonBuck commentedon Feb 15, 2024
I should have been clearer - the WebAssembly runtime (as in the code from the
.Clientproject) won't actually start until all.wasmdownloads have completed and a component requires WebAssembly interactivity. So, if you had anInteractiveServercomponent andInteractiveWebAssemblycomponent on the same page, the starting of the WebAssembly runtime could momentarily block interactivity for theInteractiveServercomponent. But this shouldn't happen when only using theInteractiveAutorender mode. If you do see a delay like that, it's probably because theInteractiveAutocomponent is using WebAssembly interactivity.saintarian commentedon Feb 16, 2024
Thanks for the fix, @MackinnonBuck. I updated my SDK to 8.0.2 and tried on a new project and the issue looks fixed. However, I see that all the wasm files are downloaded serially (see image below). Is there a way to make this parallel (or, say 10 degrees of parallelism), while still having the websocket connection be established before the wasm is downloaded?
Andrzej-W commentedon Feb 17, 2024
@saintarian you cannot download 10 files concurrently because your application will be unusable. Maybe it is not a problem on high speed fiber Internet connection but try to download a few files concurrently using cellular network and check latency with ping command.
setroycity commentedon Feb 18, 2024
Regarding the content here, the official document does not seem to provide a detailed explanation. Would you like to supplement this document
Merged PR 36408: [release/8.0] [Blazor] Auto render mode improvements
bcookew commentedon Feb 20, 2024
It may be unrelated and specific to something I have done in my app but... Is anyone having difficulty with InteractiveAuto since the last update when using:

@rendermode @(new InteractiveAutoRenderMode(prerender: false))The page I am trying to render is injecting services from the WASM service collection which is why I am not pre-rendering.
Page loads no issues with
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))But when using auto I get nothing loading and if I navigate to another page I get a circuit exception.
The component loads normally if I refresh the page once or twice. Maybe a BrowserLink / Debugging issue?
I did notice that after navigating to the page the DevTools Debugger does briefly hold on an unhandled exception but even with "Pause on uncaught exceptions" ticked it jumps over it so quickly I can't catch it.
Edit:
I was not trying to use
prerender = falseprior to the 8.0.2 update so I don't know if this is new behavior since the changes talked about above.danielgreen commentedon Feb 20, 2024
@bcookew If the page initially loads in server mode then it will be trying to resolve the injected dependencies from the server side service provider. The dependencies will need to be present there, if they're not that could explain the problems.
bcookew commentedon Feb 20, 2024
Good offer. That was, in truth, where I started my day. I had a look at the MS Docs related to render modes here. And followed their advice to set prerender to false. This did indeed clear the DI issue but left me with this odd behavior where the page never loads unless I refresh a couple of times.
Open to further thoughts / discussion on this for sure!
danielgreen commentedon Feb 20, 2024
@bcookew It still sounds like a DI issue. Setting prerender to false will still mean it tries to load in server (SignalR) mode initially. Then when you refresh, if the wasm resources have been downloaded by that point then after refreshing it will switch to wasm mode.
So you still need to ensure the dependencies can be resolved server side, or change the render mode from Auto to WebAssembly.
bcookew commentedon Feb 20, 2024
@danielgreen
Thanks, I will dig deeper around that.
Evengard commentedon Feb 26, 2024
I stumbled upon a similar problem. A browser which doesn't have WASM or WASM is disabled alltogether. I tested with Firefox setting javascript.options.wasm to false. I'd expect it to still work using server-side rendering. Instead, it seems like it crashes and no interactivity works.