Skip to content
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

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 12, 2024

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 of AddCascadingAuthenticationState(). However, our docs and templates reference the new AddCascadingAuthenticationState() API, and customers have expressed discontent with having to downgrade to <CascadingAuthenticationState>.

Regression?

  • Yes
  • No

The bug was introduced at the same time as the affected features/scenarios.

Risk

  • High
  • Medium
  • Low

The fix is simple; copy the list of subscribers to a separate buffer before enumerating them.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Sorry, something went wrong.

@github-actions github-actions bot requested a review from a team as a code owner August 12, 2024 17:23
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Aug 12, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 8.0.x milestone Aug 12, 2024
@MackinnonBuck MackinnonBuck added the * NO MERGE * Do not merge this PR as long as this label is present. label Aug 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Aug 20, 2024
@wtgodbe
Copy link
Member

wtgodbe commented Aug 30, 2024

@MackinnonBuck do we want this for October?

@Facialme
Copy link

Facialme commented Sep 3, 2024

Hello, @dotnet/aspnet-blazor-eng. Could you help us with this?

@javiercn
Copy link
Member

@MackinnonBuck did this fall through the cracks? I imagine we still want to merge this?

@MackinnonBuck
Copy link
Member

@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.

@MackinnonBuck MackinnonBuck added Servicing-consider Shiproom approval is required for the issue and removed * NO MERGE * Do not merge this PR as long as this label is present. labels Jan 31, 2025
@MackinnonBuck
Copy link
Member

/azp run

@dotnet-policy-service dotnet-policy-service bot removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jan 31, 2025
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@MackinnonBuck MackinnonBuck added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Feb 3, 2025
@wtgodbe
Copy link
Member

wtgodbe commented Feb 6, 2025

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@wtgodbe
Copy link
Member

wtgodbe commented Feb 7, 2025

Java failure unrelated

@wtgodbe wtgodbe merged commit fdeed3e into release/8.0 Feb 7, 2025
22 of 25 checks passed
@wtgodbe wtgodbe deleted the backport/pr-57243-to-release/8.0 branch February 7, 2025 00:48
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 8.0.x, 8.0.14 Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants