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

BlazorWebApp .Net 8 App State management #31316

Closed
vconfrence opened this issue Dec 29, 2023 · 11 comments · Fixed by #31488
Closed

BlazorWebApp .Net 8 App State management #31316

vconfrence opened this issue Dec 29, 2023 · 11 comments · Fixed by #31488
Assignees

Comments

@vconfrence
Copy link

Description

Following Carl Franklin's application state management in blazor doesn't seem to work in .Net 8.

https://www.youtube.com/watch?v=4WPuGwxZKIA

The local storage instance and the renderfragment appear to be null. in addition getting The render handle is not yet assigned when calling statehaschanged() in the cascading app state throws the following exception "The render handle is not yet assigned."

Here's the github repo the project

https://github.com/vconfrence/BlazorApp1.git

CascadingAppState component which is meant to be a root level cascading value available through cascading parameter within any compoenent doesn't seem to work. LocalStorage and other variables don't seem to be initializing.

Also followed guidelines posted by Microsoft which didn't work

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/cascading-values-and-parameters?preserve-view=true&view=aspnetcore-8.0#root-level-cascading-values

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-7.0&pivots=server#handle-prerendering

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/state-management.md

Document ID

e5e1273b-195e-5da1-b4aa-66bbcff1425b

Article author

@guardrex

Copy link
Contributor

🍂🎁 Happy Holidays! ❄️⛄

This issue has been marked for triage on the Blazor Docs GitHub project, and I'll respond as soon as I return from the holiday vacation the second week of January.

We only work on documentation on this repo. If you need product support, close this issue and seek assistance through one or more of the following support channels:

If you think that you found a potential bug in the framework or have product feedback, close this issue and open a new issue for the ASP.NET Core product unit at dotnet/aspnetcore issues. Bug reports require a clear explanation of the problem, usually including a minimal repro project placed on GitHub for the product unit engineers to download and run. If you determine with the product unit that it isn't a bug but merely requires documentation, please re-open this docs issue and place a cross-link to your engineering issue discussion.

For problems or feedback on Visual Studio, close this issue and use the Report a Problem or Suggest a Feature processes from within VS, which open internal issues for the VS product unit. For more information, see Visual Studio Feedback.

For problems with Visual Studio Code, close this issue and ask for support on community support forums. For bug reports and product feedback, open an issue on the microsoft/vscode GitHub repo.

💃🕺🥳 Happy New Year! 🎈🎆🍾🥂🎉 See you in 2024!

@guardrex
Copy link
Collaborator

Carl Franklin's application state management in blazor

We can't support third-party content for Blazor, so that would need to be taken up with him.

Also followed guidelines posted by Microsoft which didn't work

Root-level cascading values do work (and that is the correct version of the article). The approaches described and the examples are functional AFAIK. You'd need to put up a minimal repro project of the behavior that you're describing. If you can't get our guidance to work, open an issue for the product unit at ...

https://github.com/dotnet/aspnetcore/issues

... and cross-link your minimal repro project so they can see what you're doing.

Please add ...

cc: @guardrex https://github.com/dotnet/AspNetCore.Docs/issues/31316

... to the bottom of your opening comment so that I can follow along. I might re-open this for doc work depending on what they say.

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-7.0&pivots=server#handle-prerendering

You're looking at the wrong version of the article. Change your doc version selector to 8.0 for this version of the guidance ...

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-8.0&pivots=server#handle-prerendering

@github-project-automation github-project-automation bot moved this from Triage to Done in Blazor.Docs Dec 29, 2023
@vconfrence
Copy link
Author

Appreciate the comments. Here's the repo containing an example which shows root level cascading not working.
https://github.com/vconfrence/BlazorApp1.git

@vconfrence
Copy link
Author

Hi everyone. any suggestions/comments would be greatly appreciated.

@guardrex
Copy link
Collaborator

It looks like you followed the guidance correctly. The product unit will need to investigate on the PU issue that you opened. I'm 👂 over there for how it turns out. The reason that responses are so slow right now is that they have a large backlog of Blazor Web App/8.0 issues to address. Hopefully, they'll reach your issue soon.

@guardrex
Copy link
Collaborator

I see Steve just responded. That's kind'a challenging to get into a thumbnail remark, but I'm distilling it down to something like ...

Registering a cascading value doesn't register services or activate DI for the registered type. Treat services separately from cascading values, registering them separately from the cascading value and injecting them where the cascading value is consumed.

... 🤔 something like that 😆.

@guardrex guardrex reopened this Jan 17, 2024
@github-project-automation github-project-automation bot moved this from Done to Triage in Blazor.Docs Jan 17, 2024
@guardrex
Copy link
Collaborator

... but 🤔 .........

https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-8.0&pivots=server#factor-out-the-state-preservation-to-a-common-location

Hummmmmmmm ... I need to look at that a little closer compared to what you did.

@guardrex
Copy link
Collaborator

Idk @vconfrence ... did you not register ILocalStorageService ... is that something that the Blazored services register? It kind'a seems like compared to the state preservation approach that your code would work in spite of what Steve said. It's clearly a very similar approach.

@guardrex
Copy link
Collaborator

I'll wait to see if Steve reacts to my remark on the PU issue. The best I can do thus far in terms of a doc update is ...

On its own, registering a cascading value doesn't register additional services that the cascaded type uses. Treat required services separately from cascading values, registering them separately from the cascaded type.

... but like I said ... that doesn't really address the problem that you ran into. AFAICT, you did that already and already knew that. 😄

@guardrex guardrex moved this from Triage to P2 - Medium Priority in Blazor.Docs Jan 17, 2024
@guardrex guardrex moved this from P2 - Medium Priority to 8.0 in Blazor.Docs Jan 17, 2024
@guardrex
Copy link
Collaborator

Ok ... getting closer to something that I can cover, but it looks like we still don't have an answer on wrapping the Router with the component. That is actually just like what we show.

@guardrex
Copy link
Collaborator

Latest stab 🔪 at text would be something like ...

Registering a component type as a root-level cascading value doesn't register additional services or permit service activation in the component. Treat required services separately from cascading values, registering them separately from the cascaded type. Wrap the Router in the Routes component or the Routes component in the App component with the component registered as the cascading value, and avoid using AddCascadingValue to register the component type.

... and I see a bit of text that I need to update separately in the 8.0 state management doc, where it states ...

To make the state accessible to all components in an app, wrap the CounterStateProvider component around the Router in the App component (App.razor):

That needs to be updated for 8.0.

... AND I need to place a cross-link from the Cascading values and params article to the State management article in an Additional resources section added to the doc.

@guardrex guardrex added the Pri1 label Jan 17, 2024
@guardrex guardrex moved this from 8.0 to In progress in Blazor.Docs Jan 17, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Blazor.Docs Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants