vite icon indicating copy to clipboard operation
vite copied to clipboard

Vite reloads when idle for some time

Open Nefcanto opened this issue 1 year ago • 3 comments

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

  1. Create a Vite+React app
  2. Run the app
  3. Whenever the app loads, print the current date-time in the console
  4. Go do something else that takes time
  5. 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

Nefcanto avatar Aug 10 '24 05:08 Nefcanto

Its just a hunch but maybe

  1. 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.
  2. 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 avatar Aug 10 '24 07:08 KailasMahavarkar

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

Nefcanto avatar Aug 10 '24 08:08 Nefcanto

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:

  1. The page lost connection to the Vite websocket server, it'll ping the server until reconnects, and then reload.
  2. HMR fails due to circular imports and requires a reload.
  3. The Vite server manually sends a full-reload websocket event.
  4. 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.

bluwy avatar Aug 14 '24 08:08 bluwy

Closing as can't be reproduced.

bluwy avatar Nov 06 '24 09:11 bluwy