"prerender: false" is ignored in child components #55635
Labels
area-blazor
Includes: Blazor, Razor Components
bug
This issue describes a behavior which is not expected - a bug.
feature-prerendering
Issues related to prerendering blazor components
Milestone
prerender: false
innew InteractiveWebAssemblyRenderMode(prerender: false)
and its Server/Auto counterparts only seems to have an effect for top-level render modes. If a parent component specifies a render mode, theprerender
configuration of all its children are completely ignored.#53462 reported a similar issue where
prerender: true
is ignored for child components if a parent component specifiesprerender: false
. This was closed as by design. IIt makes sense for that particular scenario, because if a child component can pre-render, that doesn't necessarily mean it needs to. And there's no way for the Blazor to know what child components exist during prerendering if the parent is not prerendered, so it's not even detectable until later during interactive rendering.Ignoring
prerender: false
is worse mostly because it is possible to not prerender these child components during its parent's prerendering pass, so Blazor developers could easily expect this to work. Furthermore, it's likely that a child component that explicitly asks forprerender: false
is doing something like JS interop which fails during prerendering.If we really cannot make this work, it should at least raise an error like we do when a child component tries to specify a rendermode that incompatible with its parent. (e.g.
System.NotSupportedException: Cannot create a component of type 'BlazorApp1.Client.Pages.Counter' because its render mode 'Microsoft.AspNetCore.Components.Web.InteractiveWebAssemblyRenderMode' is not supported by interactive server-side rendering.
) I'd prefer to make this scenario work though.halter73/BlazorChildComponentPrerenderFalse@bb6108e shows the modifications you can make to the
dotnet new blazor -int WebAssembly
project template to demonstrate the error. It updates theCounter
component to includeprerender: false
and addsif (!OperatingSystem.IsBrowser()) throw ...
inOnInitialize
. This will not throw if you navigate directly to/counter
, but it also addsCounter
as a child toCounterParent
which allows prerendering. So, if you navigate to/counter-parent
, you'll see the exception.This repro just happens to be based on the WebAssembly project template, but the same problem exists for interactive server and auto rendermodes.
The text was updated successfully, but these errors were encountered: