Skip to content

[Blazor] Auto Render not working properly in .NET 8 and page locks until WebAssembly start #52154

Closed

Description

@AmBplus

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

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.
lockPage

Activity

  1. ghost added
    area-blazor
    on Nov 17, 2023
  2. 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
  3. danroth27 commented on Nov 17, 2023

    @danroth27
    Member

    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

  4. carlfranklin commented on Nov 17, 2023

    @carlfranklin

    I’m seeing the same thing

  5. ray440 commented on Nov 17, 2023

    @ray440

    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 delay is expected but much longer than expected leading to a stalled UX for antsy users.

    Is there a way to tell what @rendermode is?

  6. danroth27 commented on Nov 17, 2023

    @danroth27
    Member

    Is there a way to tell what @rendermode is?

    Not currently: #49401

  7. carlfranklin commented on Nov 17, 2023

    @carlfranklin
  8. mkalinski93 commented on Nov 18, 2023

    @mkalinski93

    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.

  9. SteveSandersonMS commented on Nov 20, 2023

    @SteveSandersonMS
    Member

    @carlfranklin I’m seeing the same thing

    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?

  10. AmBplus commented on Nov 20, 2023

    @AmBplus
    Author

    @SteveSandersonMS (usually< 500ms, but depends on CPU speed)

    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.

  11. carlfranklin commented on Nov 20, 2023

    @carlfranklin
  12. ziaulhasanhamim commented on Nov 22, 2023

    @ziaulhasanhamim

    @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.

  13. SteveSandersonMS commented on Nov 22, 2023

    @SteveSandersonMS
    Member

    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).

  14. ziaulhasanhamim commented on Nov 22, 2023

    @ziaulhasanhamim

    @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.

  15. AmBplus commented on Nov 22, 2023

    @AmBplus
    Author

    @ziaulhasanhamim , Try Publish And See Still Have Delay

  16. 62 remaining items

  17. mikes-gh commented on Feb 15, 2024

    @mikes-gh
    Contributor

    @MackinnonBuck

    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?

  18. MackinnonBuck commented on Feb 15, 2024

    @MackinnonBuck
    Member

    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.

  19. saintarian commented on Feb 16, 2024

    @saintarian

    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?

    Screenshot 2024-02-16 at 5 25 46 PM
  20. Andrzej-W commented on Feb 17, 2024

    @Andrzej-W

    @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.

  21. setroycity commented on Feb 18, 2024

    @setroycity

    Regarding the content here, the official document does not seem to provide a detailed explanation. Would you like to supplement this document

  22. bcookew commented on Feb 20, 2024

    @bcookew

    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.
    image

    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.

  23. danielgreen commented on Feb 20, 2024

    @danielgreen

    @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.

  24. bcookew commented on Feb 20, 2024

    @bcookew

    @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!

  25. danielgreen commented on Feb 20, 2024

    @danielgreen

    @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.

  26. bcookew commented on Feb 20, 2024

    @bcookew

    @danielgreen
    Thanks, I will dig deeper around that.

  27. Evengard commented on Feb 26, 2024

    @Evengard

    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.

  28. locked and limited conversation to collaborators on Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-blazorbugfeature-full-stack-web-ui

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions