Skip to content

I am having trouble migrating Blazor WASM SPA project to component rendering ( mix between wasm and server render) #60748

@ITStar-WY

Description

@ITStar-WY

We migrated our Blazor WebAssembly (WASM) SPA project to use the new Blazor Web App model with component rendering modes (server and WebAssembly in different components). However, we encountered two major issues:

New Document on Navigation

Every time we navigate, a completely new document is created, causing all document-level event handlers to reset. This behavior is different from the previous WASM SPA model, where the same document persisted across navigations.
Example: We set up a global window event listener in OnAfterRenderAsync, but it is removed when navigating to another page.

Lazy-loaded CSS/JS Causes FOUC (Flash of Unstyled Content)

In our previous project, we lazy-loaded JavaScript and CSS files, improving initial load times.
Now, when the app starts, the first visual is just barebones HTML with no styles applied, resulting in an ugly unstyled UI until the CSS loads.
Previously, in WASM SPA, styles were bundled and available immediately, but now they load asynchronously, causing layout shifts.

Additionally, OnAfterRender in Main Layout No Longer Works for JS Interop
In our previous WASM SPA, we used OnAfterRender in the Main Layout to call JavaScript interop (e.g., initializing third-party libraries or setting up global scripts, authentication).
With component rendering, this method is no longer reliably triggered, breaking our JS initialization.
This impacts scripts that rely on layout-level logic rather than per-page initialization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Status: No Recent Activityarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions