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
Using per page/component render modes, cascading parameters turn null after rendering. #53482
Comments
@carlfranklin thanks for reaching out. This is likely because you are trying to pass the cascading parameters across serialization boundaries (which is not generally supported) There's a bug tracking support for this type of thing here, however, in general the values will have to be serializable #51969 |
I think the problem here is that Routes.razor which contains the CascadingState is not marked as Interactive, so it does not participate in the interactivity. If you mark Routes as Interactive, this problem goes away. I guess you could also move the CascadingState to a new layout that is marked Interactive and have any Interactive routable pages use the new layout. There may be other ways of course, but it doesn't seem like a bug that state parented in a non-interactive component is null. |
If you mark Routes as Interactive, isn't that effectively Global mode?
The goal is to have state accessible even when switching between Server and
Wasm render modes, and even if you go to a SSR page and back.
It may not be a bug, but it means using per page/component mode (not
Global) means giving up Cascading values, and therefore giving up state.
…On Wed, Jan 31, 2024 at 6:57 AM SQL-MisterMagoo ***@***.***> wrote:
I think the problem here is that Routes.razor which contains the
CascadingState is not marked as Interactive, so it does not participate in
the interactivity.
If you mark Routes as Interactive, this problem goes away.
I guess you could also move the CascadingState to a new layout that is
marked Interactive and have any Interactive routable pages use the new
layout.
There may be other ways of course, but it doesn't seem like a bug that
state parented in a non-interactive component is null.
—
Reply to this email directly, view it on GitHub
<#53482 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALK4DC46UQAF7FZ2GYOAPLYRIWSZAVCNFSM6AAAAABCCALPIWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJYHE3DGOJUG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes, making routes interactive is the same effectively as global, so you
would push that down to a location where it is needed.
If you don't want everything in routes to have access to the state, move
the state down to where it is needed.
If you do want everything in routes to have access to state then it needs
to be interactive.
…On Wed, 31 Jan 2024, 14:39 Carl Franklin, ***@***.***> wrote:
If you mark Routes as Interactive, isn't that effectively Global mode?
The goal is to have state accessible even when switching between Server
and
Wasm render modes, and even if you go to a SSR page and back.
It may not be a bug, but it means using per page/component mode (not
Global) means giving up Cascading values, and therefore giving up state.
On Wed, Jan 31, 2024 at 6:57 AM SQL-MisterMagoo ***@***.***>
wrote:
> I think the problem here is that Routes.razor which contains the
> CascadingState is not marked as Interactive, so it does not participate
in
> the interactivity.
>
> If you mark Routes as Interactive, this problem goes away.
>
> I guess you could also move the CascadingState to a new layout that is
> marked Interactive and have any Interactive routable pages use the new
> layout.
>
> There may be other ways of course, but it doesn't seem like a bug that
> state parented in a non-interactive component is null.
>
> —
> Reply to this email directly, view it on GitHub
> <
#53482 (comment)>,
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/AALK4DC46UQAF7FZ2GYOAPLYRIWSZAVCNFSM6AAAAABCCALPIWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJYHE3DGOJUG4>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
—
Reply to this email directly, view it on GitHub
<#53482 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACWQFPVDVTXFHVWJMNJ6Z4DYRJJRTAVCNFSM6AAAAABCCALPIWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJZGIZTMNZVGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
There are a lot of limitations dealing with render mode boundaries... I documented a bunch of them here (including the CascadingParameter behavior): https://www.linkedin.com/posts/shaunbrucewalker_blazor-dotnet8-activity-7128497980755603456-QsnX
|
Parking in Preview 7 to provide a sample demonstrating how to do this. |
@mkArtakMSFT hopefully the ultimate resolution allows bi-directional state management - which is to say that if I change a value in a wasm page, that value should continue to be consistent in server static and server interactive pages, and visa versa. Basically, if I implement a Counter page and put the counter value in some cascading/global location, I should get the same Counter value in every render mode throughout the lifetime of a single app "session". |
I think the confusion that MS created with cascading parameters in conjunction with static SSR and interactive server-side rendering was a major mistake. |
@Otto404 you may find the following example useful: https://github.com/sbwalker/Oqtane.State It demonstrates a simple approach for using Cascading Parameters and Scoped Services in Blazor in .NET 8 when using static and interactive components. Note that it only works for the most common scenario I have seen in Blazor, where you are using Cascading Parameters and Scoped Services as essentially a "read-only immutable cache" for the current user session. |
Before leaving Blazor, I'd look at the solutions from myself and @sbwalker - I think we've come up with good answers to the challenge that make the new render modes work really well in a lot of scenarios. And the flexible render modes are (imo) very useful in real-world scenarios. |
@rockfordlhotka could you give me a pointer to your solution? thanks, |
I solved the issue without cascading parameters, instead basically creating a per-user "session" concept that is read-write across static, server-interactive, and wasm-interactive pages. |
Is there an existing issue for this?
Describe the bug
Using per page/component render modes, cascading parameters turn null after rendering.
Expected Behavior
The issue is documented with code at https://github.com/carlfranklin/Blazor8Test
Using per page/component render modes, cascading parameters turn null after rendering.
I have a .NET 8 Blazor Web App with the Interactive Render Mode set to Server, and the Interactivity Location set to Global.
This is my version info:
In App.razor, I have disabled pre-rendering, but it also fails with pre-rendering on.
I have a component in the client project called CascadingAppState.razor:
I have modified Routes.razor as follows:
I have implemented
CascadingAppState
in Counter.razor:Note that I am also showing the current render mode: SSR, Server, or WASM.
Behavior
Run the app and navigate to the Counter page. It works as advertised
Increment the counter, navigate to Home and back. The value persists because of the Cascading App State:
Now remove the "Global" feature in App.razor:
And add this line on line 2 of Counter.razor:
Run it again
Upon navigation, you get a Null Reference Exception on AppState:
Steps To Reproduce
Follow the instructions I have laid out
Exceptions (if any)
No response
.NET Version
Version info is included in description
Anything else?
No response
The text was updated successfully, but these errors were encountered: