Skip to content

Conversation

javiercn
Copy link
Member

Ensure ExecutionContext flows to hot reload re-renders

Description

  • capture the current ExecutionContext when subscribing to HotReloadManager.OnDeltaApplied
  • invoke RenderRootComponentsOnHotReload via a helper that restores the captured context, preserving AsyncLocal values
  • add a regression test that simulates hot reload and confirms AsyncLocal data survives the re-render

Fixes #45741

Customer Impact

AsyncLocal-backed data (e.g., culture, logging scopes, circuit state) was being lost after hot reload, leading to incorrect behavior on subsequent renders.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Changes are scoped to the hot reload subscription path, reuse existing render logic, and are exercised by automated tests.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Sep 26, 2025
@javiercn javiercn marked this pull request as ready for review September 26, 2025 16:49
@javiercn javiercn requested a review from a team as a code owner September 26, 2025 16:49
@Copilot Copilot AI review requested due to automatic review settings September 26, 2025 16:49
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where AsyncLocal values were being lost during hot reload operations in Blazor applications. The core problem was that hot reload callbacks executed without the original ExecutionContext, causing AsyncLocal-backed data (culture, logging scopes, circuit state) to disappear after hot reload.

  • Captures the ExecutionContext when subscribing to hot reload events during root component registration
  • Creates a helper class to restore the captured context when invoking hot reload re-renders
  • Adds a regression test that confirms AsyncLocal values survive hot reload operations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Components/Components/src/RenderTree/Renderer.cs Implements ExecutionContext capture and restoration for hot reload callbacks
src/Components/Components/test/RendererTest.cs Adds regression test to verify AsyncLocal values are preserved during hot reload

@javiercn
Copy link
Member Author

/backport to release/10.0

Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/aspnetcore/actions/runs/18044715064

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blazor AsyncLocal is null on first re-render following hot reload
1 participant