-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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 component passed as cascading parameter is null when used in MainLayout.razor (.NET 8.0 RC 1) #50724
Comments
I have looked at this and can see page rendering (only the first time) with the correct cascading value, then resets and shows the default. It appears that the page is rendering twice. Here are my test cases (simplified code):
You can watch what is happening by navigating to the |
We have the same issue in Radzen.Blazor - a CascadingParameter is null in the child because of the new static rendering mode (I presume). @Stamo-Gochev Fun times ahead for us Blazor UI component developers ;) Those new blazor interactivity modes will make us cry for sure. |
@akorchev yeah, the |
@Stamo-Gochev I'm afraid cascading parameters do not pass across rendermode boundaries. There are two main aspects to understanding this:
We chose not to JSON-serialize cascading parameters because the typical usage patterns for cascading parameters are somewhat like DI services. There are often platform-specific variants of cascading parameters, so it would be unhelpful to developers if we stopped them from having Server-interactive specific versions or WebAssembly-specific versions. And many cascading parameter values in general are not serializable, so it would be impractical to update existing apps if you had to stop using all nonserializable cascading parameter values. It wouldn't even help in your case since your cascading parameter values are definitely not serializable. RecommendationIf you need to make state available to all interactive components as a cascading parameter, you'll need to use the new API we've added to enable this. In // There are also various other overloads, e.g., if you need to use a factory pattern or to emit updated values later
builder.Services.AddCascadingValue(someValue); Such values will then be available to all components, including interactive ones, since they go through the same DI container setup. Likewise you can call this from As a component library author, you could create an extension method like: builder.Services.AddTelerikCascadingParameters(); ... and instruct developers to call that, as an alternative to telling them to add your Does that make sense? |
Thanks for the info and the recommendations, @SteveSandersonMS, we will consider the suggestions. I do understand that this is actually by design taking into account the interactivity-related specifics. |
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. |
Is there an existing issue for this?
Describe the bug
When a Blazor component is used in
MainLayout.razor
in a Blazor app with Blazor Server interactive render mode, passing this component as a cascading parameter results in the component having the valuenull
.Details
The Blazor app renders a RootComponent, which basically re-renders its child content. The component wraps the
@Body
element inside MainLayout.razor and it is used together with a ContentComponent that appears on the Home.razor page.When the app is run, the first time the
ContentComponent
is initialized, theRootComponent
has its correct value, but on consecutive calls it becomesnull
.Expected Behavior
The component that is passed down the hierarchy as a cascading parameter should not be null.
Steps To Reproduce
RootComponent
value becomesnull
or see the attached GIFExceptions (if any)
The cascading value is
null
..NET Version
8.0.100-rc.1.23455.8
Anything else?
The text was updated successfully, but these errors were encountered: