-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/8.0] [Blazor] Allow cascading value subscribers to get added and removed during change notification #57288
Conversation
@MackinnonBuck do we want this for October? |
Hello, @dotnet/aspnet-blazor-eng. Could you help us with this? |
@MackinnonBuck did this fall through the cracks? I imagine we still want to merge this? |
@javiercn Yeah, we'd want to merge this. We were waiting to make sure that the .NET 9 fix didn't have any ill effects, but the feedback on the original issue is positive. So we can unblock this now. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Java failure unrelated |
Backport of #57243 to release/8.0
/cc @MackinnonBuck
Important
We're waiting to get feedback about the original change before merging this backport
[Blazor] Allow cascading value subscribers to get added and removed during change notification
Updates cascading value change notification logic to operate on a copy of the subscriber list to avoid cases where the list could get mutated during enumeration.
Fixes #53075
Description
.NET 8 included changes to improve the flexibility of cascading values. One of these improvements enabled root-level cascading values that can be consumed by components anywhere in the component hierarchy.
The
AddCascadingAuthenticationState()
API utilizes root-level cascading values to simplify making the authentication state available to Blazor components. However, customers have reported that under certain circumstances, using this API can cause an exception to get thrown that ends the user's session.While
AddCascadingAuthenticationState()
manifests the bug, the root cause is actually deeper within the internals of Blazor's implementation of cascading values. If a cascading value changes, a change notification is issued to all components (subscribers) listening to that change. If a component reacts to the change by adding another subscriber (e.g., rendering another component that subscribes to the cascading value), then an exception gets thrown because the internal list of subscribers managed by the framework gets mutated as it's being enumerated.Customer Impact
Many customers have reported being impacted by this bug (see the comments in #53075).
Some customers have reported working around the issue by using a
<CascadingAuthenticationState>
component (which existed prior to .NET 8) instead ofAddCascadingAuthenticationState()
. However, our docs and templates reference the newAddCascadingAuthenticationState()
API, and customers have expressed discontent with having to downgrade to<CascadingAuthenticationState>
.Regression?
The bug was introduced at the same time as the affected features/scenarios.
Risk
The fix is simple; copy the list of subscribers to a separate buffer before enumerating them.
Verification
Packaging changes reviewed?