dotnet / dotnet/aspnetcore

Disable hot reload script from frontend

Open
#54,107 1 comment 3 reactions 0 assignees View on GitHub
area-commandlinetools feature-hot-reload
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

Originally [asked on SO](https://stackoverflow.com/q/78018366/9971404) without resolution.

### 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'm using hot reload with Razor Pages (v7).

Sometimes I make changes in my IDE and don't want the page to be reloaded in the browser after I save.

Use cases:
- I make changes to the page via the devtools, and if the page is reloaded then those changes would be lost
- I'm interacting with some remote API and don't want to lose such state

### Describe the solution you'd like

There [are ways](https://stackoverflow.com/q/68952259/9971404) to disable hot reload, but that's not what I want - I want to keep using it, but to disable it per page, on demand, from the frontend itself. For example, I want to inject a button into the page with a script that disables hot reload.

The `_framework/aspnetcore-browser-refresh.js` script is [here](https://github.com/dotnet/sdk/blob/release/7.0.2xx/src/BuiltInTools/BrowserRefresh/WebSocketScriptInjection.js).

The simplest solution is for the id to be saved to some global variable with a specific name, for example:
```js
window['hotReloadTimerId'] = setTimeout(/*...*/);
```

Then we could disable it with:
```js
clearTimeout(window['hotReloadTimerId']);
```

### Additional context

I tried this without success:
```js
window['_dotnet_watch_ws_injected'] = 1;
```
I don't know why that doesn't work.

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.