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

.NET8 render modes break RadzenComponents #1193

Closed
XorZy opened this issue Oct 12, 2023 · 2 comments
Closed

.NET8 render modes break RadzenComponents #1193

XorZy opened this issue Oct 12, 2023 · 2 comments

Comments

@XorZy
Copy link

XorZy commented Oct 12, 2023

Describe the bug
.NET8 new render modes break RadzenComponents

To Reproduce
-Create a Blazor Server App with .NET8 RC2
-Add the required js, css and services
-Add RadzenComponents to the main layout

Expected behavior
DialogService.Open should work in components with RenderModeInteractiveServer.

Actual behavior
DialogService.Open does not work, nothing happens.

This is issue, from my understanding that layouts are rendered as static components, therefore the RadzenComponents in the layout will not be accessible from any interactive component further down. It appears to be impossible to set the rendermode for a specific layout (dotnet/aspnetcore#50518).

I have found only two ways to get RadzenComponents to work with .NET8

  • You include them in any component that needs them, which seems quite cumbersome, and I am not sure what would happen if you end up having more that one Dialog in a given page.
  • Or you set the entire app to RenderModeInteractiveServer by setting @rendermode in the Routes component

With the second method you effectively lose the ability to use SSR, which can be problematic if you plan to use the new Blazor Identity Components, which do not work in interactive mode.
I don't think there is a way to make a specific component static so once the route is set to interactive any component or page will also be interactive.

Am I missing something?

What is the recommended way to add RadzenComponents with NET8?

@akorchev
Copy link
Collaborator

akorchev commented Oct 12, 2023

Duplicate of #1183. Check the linked forum thread for explanation and workarounds.

This thread also shows how to use <RadzenDialog /> in a static layout: https://forum.radzen.com/t/multiple-declarations-of-radzen-services-needed-for-net-8-rc1-render-modes/15410/2?u=korchev:

<RadzenDialog @rendermode="@RenderMode.InteractiveServer" />

@akorchev akorchev pinned this issue Oct 12, 2023
@akorchev
Copy link
Collaborator

akorchev commented Oct 12, 2023

Decided to pin this issue as I suspect this question will be asked a lot.

Here is the situation with Blazor 8 rendering modes and Blazor UI components (Radzen.Blazor or any other library or built-in component).

The default Blazor 8 web application template uses static rendering mode by default. In static mode events are not fired and components can't handle them. This is by Microsoft design and will not change. This is why components added to MainLayout.razor (or any other component with static render mode) won't appear to work - they will not respond to user interaction.

One cannot set a render mode for a layout (also by design) - it has to be enabled up the hierarchy for example for the <Routes /> component -> <Routes @rendermode="@RenderMode.InteractiveServer" />. This however disables static mode globally.

A workaround is to specify the render mode per component e.g. <RadzenDialog @rendermode="@RenderMode.InteractiveServer" />. This has problems too - a component with render mode set cannot have child content so you cannot set it to <RadzenPanelMenu> - its items are specified as child content.

If you want to have interactive "island" in a static page you have to define a component which has the render mode set via attribute: @attribute [RenderModeInteractiveServer] or @attribute [RenderModeInteractiveWebAssembly] or even @attribute [RenderModeInteractiveAuto]. For example

<RadzenNotification @rendermode="@RenderMode.InteractiveServer" />
<RadzenDialog @rendermode="@RenderMode.InteractiveServer" />
<RadzenLayout style="height: 400px">
    <Navigation /> <!-- This contains the interactive sidebar and toggle -->
    <RadzenBody>
        <div class="rz-p-4">
            @Body
        </div>
    </RadzenBody>
    <RadzenFooter>
        Footer
    </RadzenFooter>
</RadzenLayout>

There are Radzen.Blazor components that don't use events and do not require any non-static render mode - RadzenCard, RadzenRow, RadzenStack, RadzenBadge and a few others.

For additional info check these threads:

https://forum.radzen.com/t/sidebar-not-working-in-net-8-rc1-experiment/15198/13
https://forum.radzen.com/t/radzen-net-8-rc1-render-mode-support/15379
https://forum.radzen.com/t/multiple-declarations-of-radzen-services-needed-for-net-8-rc1-render-modes/15410

@enchev enchev unpinned this issue Sep 11, 2024
@enchev enchev pinned this issue Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants