phetch icon indicating copy to clipboard operation
phetch copied to clipboard

Exception when using ServiceSide Blazor with shared Endpoints

Open Talwynox opened this issue 8 months ago • 2 comments

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?

Talwynox avatar Mar 12 '25 14:03 Talwynox

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?

Jcparkyn avatar Mar 13 '25 11:03 Jcparkyn

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.

Talwynox avatar Mar 13 '25 12:03 Talwynox