mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.22k stars 139 forks source link

throw an exception in ~DisposableCallback when refresh page #414

Closed neozhu closed 1 year ago

neozhu commented 1 year ago
image

DisposableCallback with Id ""StateSubscriber.Subscribe" (created in "C:\Data\Mine\Code\Fluxor\Source\Lib\Fluxor\StateSubscriber.cs" on line 50)" was not disposed. See https://github.com/mrpmorris/Fluxor/tree/master/Docs/disposable-callback-not-disposed.md for more details

mrpmorris commented 1 year ago

Can you provide a repro, please.

neozhu commented 1 year ago

this project for your testing https://github.com/neozhu/CleanArchitectureWithBlazorServer/tree/fluxor Of course, you can also refresh the page multiple times in your project and it should also report an error

codedevote commented 1 year ago

I believe I am seeing the same issue in my Blazor Server app. I went through all the points in https://github.com/mrpmorris/Fluxor/blob/master/Docs/disposable-callback-not-disposed.md and wasn't able to fix the problem. The app is working fine until I hit the browser refresh button, which causes the exception being thrown as described in initial post. I can try to help here with a PR or further analysis, but I would need some guidance on how to tackle this. If you can share a few hints on how to approach this I can try to further analyze and contribute a PR if required.

neozhu commented 1 year ago

@codedevote I have already resolved the issue by adding a FetchDataAction to query the state during component initialization. Let me know if you have any further questions.

codedevote commented 1 year ago

@codedevote I have already resolved the issue by adding a FetchDataAction to query the state during component initialization. Let me know if you have any further questions.

@neozhu Can you please explain what the root cause of the problem was and how it was solved by adding a FetchDataAction? It sounds like there was something missing at that point when it was refreshed? I do have an action that initializes state in the beginning, though I am not sure, what could be still wrong on my end. Thanks for your response, I really appreciate your help.

neozhu commented 1 year ago

@codedevote Please review my code on GitHub at https://github.com/neozhu/CleanArchitectureWithBlazorServer/tree/main/src/Application/Features/Fluxor for a better understanding of how the issue was resolved. Let me know if you have any further questions.

mrpmorris commented 1 year ago

@neozhu what did you do, and why does it work?

neozhu commented 1 year ago

My scenario is as follows: I have a UserProfileState that displays the UserProfile in different Blazor Components. When the UserProfile changes, all Blazor Components are notified to refresh. Originally, I queried the database directly to get the UserProfile when the user logged in or when the page was initialized, and then called IDispatcher.Dispatch(new UserProfileUpdateAction()). This worked fine if the page was not refreshed (F5), but if I refreshed the page with F5, an error occurred. I think the reason is that Javascript is not ready yet. So, when I need to get the UserProfile from the database, I used the Effects example provided in the project to get the data through FetchUserDtoAction and FetchUserDtoResultAction. I think this is the correct approach. Thank you very much.

codedevote commented 1 year ago

@neozhu Thanks for response, unfortunately, I am not able to map that to my scenario.

@mrpmorris How would I approach debugging this? I am thinking of cloning the repo and using it as a project reference instead of your nuget packages. I could then add some more tracking code and debug my way through. Any further suggestions are highly appreciated. Thanks.

mrpmorris commented 1 year ago

@neozhu I ran your app and hit refresh multiple times but saw no errors.

Which page should I navigate to, and what should I do once there?

neozhu commented 1 year ago

I have fixed it

mrpmorris commented 1 year ago

@neozhu How did you fix it?