-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/8.0] [Blazor] Invoke inbound activity handlers on circuit in…
…itialization (#57715) Backport of #57557 to release/8.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](https://learn.microsoft.com/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-8.0#access-server-side-blazor-services-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](#57481) 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 - [X] No The problem has existed since the introduction of the feature in .NET 8. ## Risk - [ ] High - [ ] Medium - [X] 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 - [X] Manual (required) - [X] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A
- Loading branch information
1 parent
23cb501
commit 30ef19c
Showing
6 changed files
with
39 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 1 addition & 23 deletions
24
...assets/Components.TestServer/RazorComponents/Pages/Interactivity/CircuitContextPage.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,3 @@ | ||
@page "/interactivity/circuit-context" | ||
@rendermode RenderMode.InteractiveServer | ||
@inject TestCircuitContextAccessor CircuitContextAccessor | ||
|
||
<h1>Circuit context</h1> | ||
|
||
<p> | ||
Has circuit context: <span id="has-circuit-context">@_hasCircuitContext</span> | ||
</p> | ||
|
||
@code { | ||
private bool _hasCircuitContext; | ||
|
||
protected override async Task OnAfterRenderAsync(bool firstRender) | ||
{ | ||
if (firstRender) | ||
{ | ||
await Task.Yield(); | ||
|
||
_hasCircuitContext = CircuitContextAccessor.HasCircuitContext; | ||
|
||
StateHasChanged(); | ||
} | ||
} | ||
} | ||
<CircuitContextComponent @rendermode="RenderMode.InteractiveServer" /> |