Vite reloads when idle for some time
Describe the bug
I'm using Vite + React. The app is up and running inside the browser, and it's connected to an API that is in debug mode with some breakpoints in it. For some reason whenever I have to follow another task (like answering an email, or installing another app on Linux, etc.) I see that VS Code comes up with the breakpoint being activated and I realize that the Vite+React app is reloaded for no reason. Nobody refreshed the app, nobody changed anything server-side, and nobody did anything with the source code or the app.
Reproduction
no production
Steps to reproduce
- Create a Vite+React app
- Run the app
- Whenever the app loads, print the current date-time in the console
- Go do something else that takes time
- Come back and you see new dates printed (meaning that the app has reloaded many times)
System Info
System:
OS: Linux 6.8 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Memory: 7.95 GB / 15.50 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
Binaries:
Node: 20.16.0 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
npmPackages:
@vitejs/plugin-react-swc: ^3.7.0 => 3.7.0
vite: ^5.3.4 => 5.4.0
Used Package Manager
npm
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Its just a hunch but maybe
- OS is allocating memory to your browser and de-allocating memory when you are not using it, so when you come back it reloads itself.
- HMR(hot module replacement) related issue
Suggestion: Temporarily disable HMR to see if the issue occurs again, edit or add these config to vite.config.js
module.exports = {
devServer: {
hot: false,
liveReload: false
}
}
I feel its more of environment dependent issue rather than vite? anyways to debug further @Nefcanto can you please share minimal reproduceable image for same issue?
@KailasMahavarkar, I don't know what image can I share. Vite just reloads. No debug info, nothing in the terminal, nothing in the browser's console.
I'll test that config.
I don't think there's anything we can do with this information. The times where Vite will reload itself is in this file (location.reload): https://github.com/vitejs/vite/blob/67005949999054ab3cd079890ed220bc359bcf62/packages/vite/src/client/client.ts
Particularly:
- The page lost connection to the Vite websocket server, it'll ping the server until reconnects, and then reload.
- HMR fails due to circular imports and requires a reload.
- The Vite server manually sends a
full-reloadwebsocket event. - The page has an error overlay and the next HMR update will reload it.
I'd suggest trying to debug this yourself and see if any of those are causing it.
Closing as can't be reproduced.