dotnet / dotnet/aspnetcore

Give the ability to devs to trigger manually hot reloads

Open
#59,383 0 comments 0 reactions 0 assignees View on GitHub
area-commandlinetools enhancement feature-hot-reload
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

### Is your feature request related to a problem? Please describe the problem.

I have been looking for a manner to trigger a hot reload in my browser after a service reloads some JSON files.

I don't want the watcher to consider my changes to the JSON files as rude edits, so I'm not adding them to the list of watched files. I have already provided a mechanism for developers to reload the files via a PhysicalFileProvider, copying the files from the source path to the debug build path, and reloading them in memory when a debugger is attached or the environment variables for DOTNET_WATCH is 1. But I have found no way to let the browser know that it should refresh. I have tried sending empty updates via `MetadataUpdater.ApplyUpdate` as a hackish way to trigger a notification, but that (expectedly) failed.

I think it would help tremendously the DX, especially for those of us working on new libraries.

### Describe the solution you'd like

A simple class injected (or not) that gives you a a watcher context, fulfilling this contract:

```csharp
interface IWatcherContext
{
bool HasWatcher { get; } // Is the application running through dotnet watch?
bool IsHotReloadEnabled { get; } // Is the hot reload option enabled
bool IsBrowserRefreshEnabled { get; } // Is browser refresh option enabled
void NotifyBrowser(); // Notifies the browser that it needs to refresh.
// ...
}
```

### Additional context

_No response_

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.