-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
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.