phetch
phetch copied to clipboard
Exception when using ServiceSide Blazor with shared Endpoints
One thing I noticed when using Phetch with server side Blazor is that the UseEndpoints Component always result in a
System.InvalidOperationException: 'The current thread is not associated with the renderer's synchronization context.
The issues seem to be https://github.com/Jcparkyn/phetch/blob/047e4b94c4a1079859ce5409c2e56aff4d8bfb87/src/Phetch.Blazor/UseEndpointBase.cs#L60-L74
When I changed StateChanged to InvokeAsync(StateChanged) everything works fine.
Is this simply an oversight or is there another reason why StateChanged is used?
Phetch isn't really intended for server-side Blazor, so I've never tested it there and I suspect there will be other problems (e.g. thread safety) beyond just this.
I'd be curious to hear more about your use-case and why you need Phetch in a server-side app?
I figured that Phetch was not primarily designed for server-side Blazor, but from my experience, it works fine with server-side Blazor except for the issue mentioned above. (Which also only occurs once you start to share endpoints across multiple scopes)
For my use case, I have an application that fetches data that is computationally heavy, so cashing is key. I also have to handle the refetching on the server and then re-render all the clients when the data has changed. So far Phetch worked pretty well for this use case.