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

Blazor SSR - can't wrap layout Body with interactive component #50518

Closed
1 task done
konstantin-karpukhin opened this issue Sep 5, 2023 · 2 comments
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@konstantin-karpukhin
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Error caused by:
-'attribute [RenderModeServer]' in layout razor
or
-'rendermode="RenderMode.Server"' on component with layout Body inside

Component.razor:

@ChildContent

@code {
    [Parameter]
    public RenderFragment ChildContent { get; set; }
}

MainLayout.razor:

<Component @rendermode="@RenderMode.Server">
    @Body
</Component>

If you have multiple layouts in your application it would useful to make some of them interactive.

Expected Behavior

No response

Steps To Reproduce

https://github.com/konstantin-karpukhin/BlazorSSRInteractiveLayout/tree/main

Exceptions (if any)

InvalidOperationException: Cannot pass the parameter 'Body' to component 'MainLayout' with rendermode 'ServerRenderMode'. This is because the parameter is of the delegate type 'Microsoft.AspNetCore.Components.RenderFragment', which is arbitrary code and cannot be serialized.
Microsoft.AspNetCore.Components.Endpoints.SSRRenderModeBoundary.ValidateParameters(IReadOnlyDictionary<string, object> latestParameters)

.NET Version

No response

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Sep 5, 2023
@javiercn
Copy link
Member

javiercn commented Sep 5, 2023

@konstantin-karpukhin thanks for contacting us.

The issue here is by design. We don't support switching render modes back and forth, as we can't serialize the delegate. Interactive components must have serializable parameters without cycles (which discards the delegate)

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Sep 5, 2023
@ghost ghost added the Status: Resolved label Sep 5, 2023
@ghost
Copy link

ghost commented Sep 6, 2023

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Sep 6, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 6, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants