web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.31k stars 543 forks source link

[Bug]: HMR stops working if server is down when HMR is attempted #6011

Open marco2216 opened 6 months ago

marco2216 commented 6 months ago

System Info

System: OS: macOS 13.3.1 CPU: (8) arm64 Apple M1 Memory: 41.08 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.8.1 - ~/.nvm/versions/node/v20.8.1/bin/node npm: 10.1.0 - ~/.nvm/versions/node/v20.8.1/bin/npm Watchman: 2023.10.23.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 123.0.6312.58 Safari: 16.4

Details

It's not a rspack issue per se, it's from the webpack HMR source. If the request to get the updated manifest fails, we get stuck in the "check" status, which means that HMR will not work, even after the server is back up. This is quite annoying for our project because sometimes the server gets restarted at the same time as a HMR is attempted.

I think it could make sense to catch here, and set state to "idle", if the request fails?

Reproduce link

No response

Reproduce Steps

Run any dev server project with HMR, close server that serves files, update a file to trigger HMR. You should see something like this in console

image

Now, notice that saving any file after this will not trigger any requests, because the status is not reset. In effect HMR is broken until the page is refreshed.

LingyuCoder commented 6 months ago

Before version 1.0, in order to ensure correctness of behavior, the runtime module of rspack would align with webpack as much as possible.

If an error is caught here, it will still need to notify the webpack dev server's runtime to retry. After the retry, it will also need to re-trigger the checking of webpack hmr runtime. This may require a relatively large refactoring, which will be considered after version 1.0 when rspack is stable.

stale[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!