dotnet / dotnet/aspnetcore

Provide full `updateTypes` to MetadataUpdateHandlers

Open
#52,937 2 comments 1 reaction 0 assignees View on GitHub
area-blazor bug feature-hot-reload Pillar: Dev Experience Priority:1
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Using Hot Reload should provide the updated types that the HotReload workspace is generating. At present time, the browserlink integration does not fill the updatedTypes parameter properly when deltas are sent.

The `aspnetcore-browser-refresh.js` contains this:

```js
let applyError = undefined;
if (window.Blazor?._internal?.applyHotReload) {
// Only apply hot reload deltas if Blazor has been initialized.
// It's possible for Blazor to start after the initial page load, so we don't consider skipping this step
// to be a failure. These deltas will get applied later, when Blazor completes initialization.
deltas.forEach(d => {
try {
window.Blazor._internal.applyHotReload(d.moduleId, d.metadataDelta, d.ilDelta, d.pdbDelta)
} catch (error) {
console.warn(error);
applyError = error;
}
});
}
```

And while `d.updatedTypes` exists, this member is not passed to `window.Blazor._internal.applyHotReload`:

![image](https://github.com/dotnet/aspnetcore/assets/5839577/baec1744-69a4-4fe5-9006-450c7441517a)

### Expected Behavior

`updatedTypes` should not be empty when a type member is hot reloaded in Visual Studio.

### Steps To Reproduce

Add the following to a blazor webassembly app:

```csharp
[assembly:MetadataUpdateHandler(typeof(MyHandler))]

static class MyHandler
{
static void ClearCache(Type[]? updatedTypes)
{
Console.WriteLine("ClearCache: " + string.Join(",", updatedTypes.Select(t => t.ToString())));

}
static void UpdateApplication(Type[]? updatedTypes)
{
Console.WriteLine("UpdateApplication: " + string.Join(",", updatedTypes.Select(t => t.ToString())));
}
}
```

### Exceptions (if any)

None.

### .NET Version

8.0.100

### Anything else?

It is likely that such a change will require:
https://github.com/dotnet/aspnetcore/blob/4b7810723c27d47cc982055c6615cccf664e2980/src/Components/WebAssembly/WebAssembly/src/HotReload/WebAssemblyHotReload.cs#L46

To be updated to use `updatedTypes` in the same fashion that dotnet/sdk uses it:

https://github.com/dotnet/sdk/blob/50ccc948eb082d316158b709301b28c5e7f60c01/src/BuiltInTools/DotNetDeltaApplier/HotReloadAgent.cs#L230

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.