dotnet / dotnet/aspnetcore

Hot reload doesn't keep state when multiple static files are changed at once

Open
#54,942 0 comments 0 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

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

When using `dotnet watch` and a bundler like vite to bundle and minify assets, the hot reload fails to keep the state of HTML elements like form inputs.

For example:
Given a form like:
![image](https://github.com/dotnet/aspnetcore/assets/1363512/98fdae6d-6716-4a5a-91a2-c370a47bd6b9)
Updating the css to explicitly set the background color of inputs to white triggers multiple files to update.
```
dotnet watch ⌚ Files changed: .\wwwroot\assets\js\chunks\asyncExample.js, .\wwwroot\assets\asyncExample.css, .\wwwroot\assets\js\main.js, .\wwwroot\assets\main.css
dotnet watch 🔥 Hot reload of static file succeeded.
dotnet watch 🔥 Hot reload of static file succeeded.
dotnet watch 🔥 Hot reload of static file succeeded.
dotnet watch 🔥 Hot reload of static file succeeded.
```
This results in the form losing it's state.
![image](https://github.com/dotnet/aspnetcore/assets/1363512/f37a3037-d68b-4bac-b56c-543195cf880b)

However if only one type of file (eg. .css) changes then it works as expected. And the form keeps its current state while updating the styling. To illustrate this I've added this item group to my .csproj file.
```



```
![image](https://github.com/dotnet/aspnetcore/assets/1363512/853b6b57-7907-481d-aba0-cd54b69bc455)
Changing the background color again.
```
dotnet watch ⌚ Files changed: .\wwwroot\assets\asyncExample.css, .\wwwroot\assets\main.css
dotnet watch 🔥 Hot reload of static file succeeded.
dotnet watch 🔥 Hot reload of static file succeeded.

```
![image](https://github.com/dotnet/aspnetcore/assets/1363512/e7570d02-566a-43d1-9b32-ee778fd3177a)

### Expected Behavior

When only static assets change i expect the form state to remain the same

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0.200

### Anything else?

_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.