mrpmorris / Fluxor

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

Fluxor breaks ErrorBoundary in Blazor Wasm #463

Closed cluka closed 3 months ago

cluka commented 7 months ago

I'm having a problem where the error page of ErrorBoundary does not show when using Fluxor in Blazor wasm 8.

I think this is because the exception is caught during control render sequence. So when Using Dispatcher.Dispatch(action)

and an exception occurs, I get

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Exception of type 'MyApp.Errors.ServerValidationException'

and I get

An unhandled error has occurred. Reload

message and the error page of the ErroBounday is NOT shown.

But if I don't use Fluxor and only do a classic service call, the error page of the ErrorBoundary is show.

Is there a way to fix this?

mrpmorris commented 3 months ago

Effects are not called within a component, they run in the background as if no UI even existed, so there are no boundaries.

StoreInitializer has a callback where you can trigger some code when an unhandled exception is encountered in an effect, but that won't help with boundaries.

Your state is an app-wide thing. If you experience an error that you weren't expecting then you cannot guarantee that data is now in a consistent and acceptable state - which means your app state in general cannot be trusted.

EliseoDiegoViola commented 3 months ago

Adding a comment here since the last one is pretty new.

Im having this same issue, but there is something that I dont understand.

@mrpmorris

Effects are not called within a component, they run in the background as if no UI even existed, so there are no boundaries.

The Fluxor.Blazor.Web.StoreInitializer is a component, and is the one that catches the exceptions inside the effects and re-throws them inside the render cycle (OnAfterRender specifically).

image

So if the ErrorBoundary->ChildContent have the store initializer inside it should work correctly, right? Because it isn't.