Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"prerender: false" is ignored in child components #55635

Open
halter73 opened this issue May 9, 2024 · 0 comments
Open

"prerender: false" is ignored in child components #55635

halter73 opened this issue May 9, 2024 · 0 comments
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

Comments

@halter73
Copy link
Member

halter73 commented May 9, 2024

prerender: false in new 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, the prerender 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 specifies prerender: 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 for prerender: 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 the Counter component to include prerender: false and adds if (!OperatingSystem.IsBrowser()) throw ... in OnInitialize. This will not throw if you navigate directly to /counter, but it also adds Counter as a child to CounterParent 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.

@halter73 halter73 added the area-blazor Includes: Blazor, Razor Components label May 9, 2024
@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. feature-prerendering Issues related to prerendering blazor components labels May 14, 2024
@mkArtakMSFT mkArtakMSFT added this to the .NET 10 Planning milestone May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants