dotnet / dotnet/aspnetcore

Remove redundant __ASPNETCORE_BROWSER_TOOLS propagation for modern Blazor WebAssembly

Open
#68,960 1 comment 0 reactions 0 assignees View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

## Summary

Investigate removing the `__ASPNETCORE_BROWSER_TOOLS` propagation code from ASP.NET Core `main` for modern (`net10.0+`) Blazor WebAssembly applications.

The .NET WebAssembly SDK now includes a build-time Hot Reload initializer for Debug builds targeting .NET 10 or later. That initializer configures the browser runtime directly:

```js
config.environmentVariables["DOTNET_MODIFIABLE_ASSEMBLIES"] = "debug";
config.environmentVariables["__ASPNETCORE_BROWSER_TOOLS"] = "true";
```

As a result, the server-process marker no longer appears necessary for activating the modern browser Hot Reload agent.

## Current ASP.NET Core code

Two locations on `main` still propagate the marker:

1. `src/Components/WebAssembly/Server/src/ComponentsWebAssemblyApplicationBuilderExtensions.cs`
- Reads `__ASPNETCORE_BROWSER_TOOLS` from the server process.
- Emits the `ASPNETCORE-BROWSER-TOOLS` response header for WebAssembly framework requests.

2. `src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs`
- Reads the same server-process variable.
- Copies it into `InteractiveWebAssembly.EnvironmentVariables` for Blazor Web Apps.

The modern SDK initializer that sets the browser-runtime variable directly is:

- https://github.com/dotnet/sdk/blob/main/src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/wwwroot/Microsoft.DotNet.HotReload.WebAssembly.Browser.lib.module.js

The browser agent consumes it here:

- https://github.com/dotnet/sdk/blob/main/src/Dotnet.Watch/HotReloadAgent.WebAssembly.Browser/WebAssemblyHotReload.cs

## Compatibility boundary

The response-header mechanism is concretely consumed by older runtimes. For example, the .NET 9 WebAssembly loader maps `ASPNETCORE-BROWSER-TOOLS` into the browser-runtime environment:

- https://github.com/dotnet/runtime/blob/release/9.0/src/mono/browser/runtime/loader/config.ts

ASP.NET Core 8 and 9 servicing branches should therefore retain their existing behavior. Removing the code from current `main` does not alter those shared-framework versions.

This issue concerns only `__ASPNETCORE_BROWSER_TOOLS`/`ASPNETCORE-BROWSER-TOOLS`. Any removal of `DOTNET_MODIFIABLE_ASSEMBLIES` propagation should be evaluated separately.

## Proposed change

Remove from ASP.NET Core `main`:

- `s_aspnetcoreBrowserTools` and its process-environment lookup.
- Emission of the `ASPNETCORE-BROWSER-TOOLS` response header.
- Injection of `__ASPNETCORE_BROWSER_TOOLS` into interactive WebAssembly runtime configuration.
- Tests that exist only to verify this legacy propagation.

## Validation

Before removal, confirm Hot Reload activation and updates continue to work for:

- A .NET 10+ hosted Blazor WebAssembly app under `dotnet watch`.
- A .NET 10+ Blazor Web App using Interactive WebAssembly under `dotnet watch`.
- The corresponding Visual Studio launch paths, if they differ from `dotnet watch` activation.
- Plain launch without browser tooling, ensuring Hot Reload remains inactive.

The expected source of truth for modern browser activation is the build-included WebAssembly initializer rather than server-process environment propagation.

Contributor guide

Open the contributing guide

Research direction

Start by reading src/Components/WebAssembly/Server/src/ComponentsWebAssemblyApplicationBuilderExtensions.cs and src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs, then locate tests that verify the legacy propagation. Confirm the modern SDK initializer and browser agent behavior, remove only the server marker/header and interactive configuration injection, and validate the listed .NET 10+ dotnet watch, Visual Studio, and plain-launch scenarios.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, wasm
Domain
backend, web-dev
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
54/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.