Issue adding static server-side rendering (SSR) pages to a globally interactive Blazor Web App
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Adding a static server-side rendering (SSR) page to a globally interactive Blazor Web App causes unnecessary page reloads, additional XHR requests, and leads to a poor user experience.
### Expected Behavior
I have a globally interactive Blazor Web App (Blazor WASM without pre-rendering). To improve performance on certain pages, I’ve added static SSR-enabled pages using the `ExcludeFromInteractiveRouting attribute`.
To enhance the user experience, I created an empty component called `WasmStarter` in the client project. In `App.razor`, when the global render mode of `` and `` is null because `HttpContext.AcceptsInteractiveRouting()` is `false`, I included `WasmStarter` with Blazor WASM render mode. This allows Blazor WASM to download and start in the background while users interact with the static SSR-enabled page content! ❤️
This approach works, but with these two issues:
1- When navigating from a static SSR-enabled page to a Blazor WASM page, Blazor sends an unnecessary XHR request to fetch that page(!). While I'm okay with re-rendering the entire DOM and losing state, the extra XHR request seems irrelevant.
2- When navigating back from a Blazor WASM page to a static SSR-enabled page, the page is completely refreshed and reloaded from the server, which disrupts the user experience. However, navigation between static SSR-enabled pages works smoothly with a simple fetch request, thanks to the Enhanced Navigation feature. I'd expect enhanced navigation works while navigating from blazor wasm enabled page to static ssr enabled page as well.
These issues result in a poor user experience. If this scenario is improved, it could significantly enhance the development of Blazor WASM-powered websites by allowing the most-visited pages to be static SSR, with Blazor WASM seamlessly loading in the background to support the rest of the site.
### Steps To Reproduce
1- Create project with `dotnet new blazor --framework net9.0 --interactivity WebAssembly --all-interactive --name BlazorSample`
2- Move `Weather.razor` from `BlazorSample.Client` to `BlazorSample` project (See changes at once in [this](https://github.com/ysmoradi/blazor-static-ssr-wasm-integration-issue/commit/0df370d66d89a7acd24077e45b0c57ad811ecd22) git commit)
3- Add `ExcludeFromInteractiveRouting` attribute to `Weather.razor`
4- Add Empty component to `BlazorSample.Client` called `WasmStarter`
5- Cascade inject HttpContext in App.razor
5- Change
```razor
```
to
```razor
```
6- Change
```razor
```
to
```razor
```
7- Add `WasmStarter` to `App.razor`
```razor
```
### Exceptions (if any)
_No response_
### .NET Version
9.0.100-preview.7.24407.12
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.