[Blazor] Invoke inbound activity handlers on circuit initialization by MackinnonBuck · Pull Request #57557 · dotnet/aspnetcore (original) (raw)
mkArtakMSFT pushed a commit that referenced this pull request
…itialization (#57678)
Backport of #57557 to release/9.0
[Blazor] Invoke inbound activity handlers on circuit initialization
Fixes an issue where inbound activity handlers don't get invoked on circuit initialization.
[!NOTE] This bug only affects Blazor Server apps, not Blazor Web apps utilizing server interactivity
Description
Inbound activity handlers were added in .NET 8 to enable:
- Monitoring inbound circuit activity
- Enabling server-side Blazor services to be accessed from a different DI scope
However, prior to the fix in this PR, this feature didn't apply to the first interactive render after the initial page load. This means that when utilizing this feature to access Blazor services from a different DI scope, the service might only become accessible after subsequent renders, not the initial render.
This PR makes the following changes:
- Updated
CircuitHost
to invoke inbound activity handlers on circuit initialization - Added an extra test to verify that inbound activity handlers work on the initial page load
- Updated existing Blazor Web tests to reuse test logic from the non-web tests
- This helps to ensure that the feature works the same way on Blazor Server and Blazor Web
Fixes #57481
Customer Impact
The initial issue report was from a customer who was impacted experiencing this problem in their app. The problem does not inherently cause an app to stop working, but if the application code has made the (rightful) assumption that the service accessor is initialized, then session may crash. The workaround is to upgrade the app to use the "Blazor Web App" pattern, although this can be a fairly large change.
Regression?
- Yes
- No
The problem has existed since the introduction of the feature in .NET 8.
Risk
- High
- Medium
- Low
The change is straightforward, and new tests have been added to ensure that it addresses the issue. Existing tests verify that a new regression is not introduced.
Verification
- Manual (required)
- Automated
Packaging changes reviewed?
- Yes
- No
- N/A