-
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
Application State in BlazorApp .Net 8 #53061
Comments
Thanks @vconfrence ... I'll keep an 👁️ on this. If there's doc work to do, we'll hear on this issue after you chat with the PU about your problem. Note that most folks are on holiday 🎆 vacation, so it could take a short while for this issue to be reached. |
@vconfrence thanks for contacting us. Your repro doesn't have any code other than the initial template. |
Hi @vconfrence. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Inside the counter page the button click triggers a call to the set property of the CascadingAppState which shows the LocalStorageService, ChildContent to be NULL and throws an exception when StateHasChanged() gets called. Here's what's embedded in the counter page @page "/counter" Counter CounterCurrent count: @currentCount <button class="btn btn-primary" @OnClick="IncrementCount">Click me @code {
} |
@vconfrence ... To place code in an issue comment use triple-backticks with a code language on a line above the code (```razor) and triple-backticks on a line below (```). It will format the code if you do that ☝️. |
Any suggestion to the stated issue would be greatly appreciated. |
Hi everyone. any suggestions/comments regarding the described issue? |
@vconfrence I think there's some confusion between DI services and cascading values. These are two separate concepts. Just because you've registered a cascading value of type You can register and consume that type as a cascading value if you want, but then you're not using DI, and hence the system isn't going to resolve other dependencies like Alternatively, and more simply, I'd recommend changing |
@SteveSandersonMS ... We seem to be using a similar approach in one of the examples. I'm not sure how @vconfrence's approach is different from it conceptually. I thought Our approach that seems quite similar is described at Factor out the state preservation to a common location ... |
In general you can't resolve a Blazor component from the DI system, at least not if you also want its |
Ok, but I thought that @vconfrence orginally tried to wrap the ... and then it looks like it was failing for @vconfrence that way, so then @vconfrence tried the root-level registration approach. Of course, I defer to @vconfrence to say if that's what happened. |
Yes, if it was done as follows, it should work: <CascadingAppState>
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
</Router>
</CascadingAppState> That's a common pattern. Not sure what wasn't working before if this was attempted. |
Cool ... we're almost there on coverage. I have some draft text just about ready to get this covered. @vconfrence ... Can you let us know what happened when you tried that ☝️? ... did it 💥 on you? UpDaTe: I'm working on it here ... Cascading values updates. I'll probably merge it tomorrow, and I'll keep an 👂 open here for further discussion. |
We have tried the suggested approach and was facing the same issue. We also tried adding builder.Services.AddCascadingValue in the program.cs and still the same issue. |
If you provide a repro that shows how you were trying to use
I hope I already clarified why calling |
Here's a repo following the approach discussed. |
Any comments/feedback would be greatly appreciated. |
@vconfrence I'm afraid there's a lot of code in the repo you posted, so it's hard to know how much of this relates to the framework and how much of it is potentially an issue in your own code. If you can reduce it down to a minimal repro (as in, does not contain any code that could be avoided while still showing the issue) we can have a look. |
There isn't much code in the application actually. you can ignore all the data objects in the data library which never get used or called. Really appreciate it if someone can look into the super simple example and provide comments or update the solution with comments to make the app state function in blazor web app. This paradigm works perfectly in blazor webassembly. |
Is there an existing issue for this?
Describe the bug
using cascading values and local storage for application state doesn't seem to work in blazor web app .net 8
cc: @guardrex dotnet/AspNetCore.Docs#31316
Expected Behavior
LocalStorage, renderfragment element of the cascadingAppState component seem to be null.
Steps To Reproduce
https://github.com/vconfrence/BlazorApp1.git
Exceptions (if any)
No response
.NET Version
8
Anything else?
No response
The text was updated successfully, but these errors were encountered: