mrpmorris / Fluxor

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

Dispatch in OnInitialized executed when navigating away from component #345

Closed forrestab closed 1 year ago

forrestab commented 2 years ago

Im trying to implement a central location or boundary to handle my custom app errors. I have an AppErrorState which holds a collection of errors and Im injecting this state into my AppErrorBoundary component. If an error occurs within an effect, I dispatch an AppErrorState action to update AppErrorState and show the errors. In order to clear these errors on navigation, I have a reducer on the GoAction which resets AppErrorState which should stop showing the errors.

Everything seems to working up to the point of reseting the AppErrorState on navigation. And to be honest, this appears to be working correctly too, but I am seeing when I navigate away from a component, that component's OnInitialized method fires again, which sets the error making it seem as though the errors werent cleared.

Ive created a simple example repo.

I new to the flux pattern and fluxor, so its possible that I have something mis-configured.

Also, Id like to get opinions on what Im trying to do as Ive searched around and haven't found this example used in many places. Is this a good way to handle app errors or is there a better way?

Thanks.

forrestab commented 2 years ago

I was able to test a little more and found out that if I comment out ResetAppError.ActionReducer (from the example repo) the OnInitialized method does not fire again when navigating away. So this leads me to believe its something Im doing wrong, but not sure what exactly?

mrpmorris commented 2 years ago

If you are able to create a repro, please file a bug with it attached.

Thanks

forrestab commented 2 years ago

@mrpmorris in the original post I provided a link to my simple repo that shows the error. Here is a link to that repo again, https://github.com/forrestab/routing-errors-and-fluxor.

mrpmorris commented 2 years ago

Last time you posted you said you were investigating further because you thought the error might be yours.

So when you didn't come back for 2 weeks, I assumed you'd fixed your code and forgotten about this report.

What did you discover?

forrestab commented 2 years ago

I appreciate you opening this back up and to be honest, im at a loss. As mentioned in my follow up, commenting out the reducer that listens for the GoAction to clear the app error boundary state stops the execution when navigating away from the component. But if i do that then im unable to clear the boundary state on navigation.

Any ideas would be appreciated? I guess what it boils down to is, is this the correct way to clear state on navigation?

Ive also verified that settings render-mode to either "Server" or "ServerPrerendered" does not resolve this problem.

forrestab commented 1 year ago

I couldn't figure out the reason for the issue and decided to go a different way.