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

Calling StateHasChanged() does not reload Page and Extension Components #88

Closed
3 tasks done
luckyluggi opened this issue Jun 24, 2022 · 2 comments
Closed
3 tasks done
Assignees
Labels
invalid This doesn't seem right

Comments

@luckyluggi
Copy link
Contributor

Bug Report

For more information, see the CONTRIBUTING guide.

Prerequisites

  • Can you reproduce the problem in a MWE?
  • Are you running the latest version?
  • Did you perform a search in the issues?

Environment Details and Version

[Package Version, Blazor Version, OS, Browser,...]

Description

Hy. I've been tracking down a problem in my app and i think i've found the source of the problem now.
I have created this mvp to show the problem:
https://github.com/luckyluggi/-mvp_piral_statehaschanged

There i have a StateContainer (my-pilet\State\ShoppingCartState.cs) with Items.
Whenever i add items i call StateHasChanged() in my-pilet\Pages\ShopPage.razor and my-pilet\Components\ShoppingCartIcon.razor but the state does not get updated.

Steps to Reproduce

see mvp

Expected behavior

Component should reload and show new state

Actual behavior

does not reload

Possible Origin / Solution

[Optionally, share your idea to fix the issue]

@luckyluggi luckyluggi added the bug Something isn't working label Jun 24, 2022
@FlorianRappl FlorianRappl added this to the v3 milestone Jun 24, 2022
@FlorianRappl FlorianRappl added blazor-v6 Applies to .NET 6.0 blazor-v5 Applies to .NET 5.0 labels Jun 24, 2022
@FlorianRappl FlorianRappl self-assigned this Jun 24, 2022
@FlorianRappl
Copy link
Collaborator

Actually the StateHasChanged works fine.

The problem is in the event handler. If you disable the first handler (just comment out the one in Shop you'll see everything updates (except the Shop). I'll investigate this.

@FlorianRappl
Copy link
Collaborator

Alright so changing the service from AddScoped to AddSingleton did the job. From official documentation:

Scoped objects are the same within a request, but different across different requests.

Apparently, we had different requests beforehand. We've seen two objects being created.

Singleton objects are the same for every object and every request.

Now we force it to be the same. And it works.

@FlorianRappl FlorianRappl added invalid This doesn't seem right and removed bug Something isn't working blazor-v6 Applies to .NET 6.0 blazor-v5 Applies to .NET 5.0 labels Jun 24, 2022
@FlorianRappl FlorianRappl removed this from the v3 milestone Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants