Skip to content

Conversation

@hakenr
Copy link
Member

@hakenr hakenr commented Nov 28, 2024

In a custom state management service, a callback invoked outside of Blazor's synchronization context must wrap the logic of the callback in ComponentBase.InvokeAsync to move it onto the renderer's synchronization context.

There isn’t a straightforward way to use ComponentBase.InvokeAsync directly in a custom state management service. Instead, each component subscribed to the OnChange event must handle it by wrapping the StateHasChanged call in InvokeAsync. This means the responsibility for ensuring synchronization with Blazor’s rendering context falls on the components themselves.


Internal previews

📄 File 🔗 Preview link
aspnetcore/blazor/state-management.md aspnetcore/blazor/state-management

@hakenr hakenr requested a review from guardrex as a code owner November 28, 2024 01:23
@guardrex guardrex self-assigned this Nov 28, 2024
@guardrex guardrex requested a review from a team December 1, 2024 20:15
Copy link
Member Author

@hakenr hakenr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@guardrex
Copy link
Collaborator

guardrex commented Dec 1, 2024

Cool ... I'll get one of the PU cats on here as soon as I can.

@SteveSandersonMS
Copy link
Member

Looks good. Thanks!

Copy link
Collaborator

@guardrex guardrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hakenr! 🎷

@guardrex guardrex enabled auto-merge (squash) December 12, 2024 10:26
@guardrex guardrex merged commit 08a87db into dotnet:main Dec 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants