vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
67.28k stars 6.05k forks source link

HMR in Vite 4.3.0-beta.3 (including 4.3.0) watches user's home folder instead of project files (in some particular case) #12926

Closed srflp closed 1 year ago

srflp commented 1 year ago

Describe the bug

Dev server in Vite 4.3.0-beta.3 (including 4.3.0), after typing in /home as an URI in the browser starts the HMR watcher on the whole user directory (~ or /home/<username>).

Our website by default opens http://localhost:<port>/home in the browser so it triggers the bug immediately.

The bug does not appear in version 4.3.0-beta.2 and below and was introduced in 4.3.0-beta.3.

After effects: in bigger projects the dev server is unusably slow and crashes because of hundred thousands of watched files.

Reproduction

Follow the steps below.

Steps to reproduce

Using linux:

  1. Create a repro folder, I created it in my home directory (~ or /home/my_username).

    mkdir ~/repro
  2. Enter this directory

    cd ~/repro
  3. Create a sample project in this directory

    pnpm create vite sample-project --template vanilla
  4. Enter the sample project folder

    cd sample-project
  5. Install dependencies

    pnpm i
  6. Run vite dev server in debug mode, to see files which are observed via HMR:

    pnpm dev -d
  7. In any browser, visit the page http://localhost:5173/home. Suspicious line appears in the terminal:

    vite:resolve 0.62ms /home -> null +38ms

    This is definitely an invalid resolution but let's move on

  8. In another terminal, enter the ~/repro folder

    cd ~/repro
  9. Create a file in this folder

    touch hello_vite
  10. Modify this file:

    vi hello_vite

    (type in any characters and save using :wq)

  11. Voila

    vite:hmr [file change] /home/<redacted>/repro/hello +3s
    vite:hmr [no modules matched] /home/<redacted>/repro/hello +1ms

    HMR reacted on this file change, even though the file isn't in the project directory (project directory is ~/repro/sample_project)

System Info

  System:
    OS: Linux 6.2 Fedora Linux 37 (Workstation Edition)
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12450H
    Memory: 21.24 GB / 31.00 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.14.0/bin/yarn
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
  Browsers:
    Chrome: 112.0.5615.49
    Firefox: 111.0.1
  npmPackages:
    vite: ^4.3.0 => 4.3.0

Used Package Manager

pnpm

Logs

The reality - hundreds of HMR reactions due to updated files in the user directory, which make vite unusable in big projects ```shell vite:hmr [file change] /home//.java/.userPrefs/.userRootModFile. +3s vite:hmr [no modules matched] /home//.java/.userPrefs/.userRootModFile. +0ms vite:hmr [file change] /home//.config/google-chrome/Default/Network Action Predictor-journal +81ms vite:hmr [no modules matched] /home//.config/google-chrome/Default/Network Action Predictor-journal +0ms vite:hmr [file change] /home//.config/google-chrome/Default/Network Action Predictor +3ms vite:hmr [no modules matched] /home//.config/google-chrome/Default/Network Action Predictor +0ms vite:hmr [file change] /home//.config/google-chrome/Default/Preferences +5s vite:hmr [no modules matched] /home//.config/google-chrome/Default/Preferences +1ms vite:hmr [file change] /home//.config/Slack/Local Storage/leveldb/001872.log +0ms vite:hmr [no modules matched] /home//.config/Slack/Local Storage/leveldb/001872.log +0ms vite:hmr [file change] /home//.config/Slack/sentry/session.json +1ms vite:hmr [no modules matched] /home//.config/Slack/sentry/session.json +0ms vite:hmr [file change] /home//.config/Slack/Cache/Cache_Data/index-dir/the-real-index +0ms vite:hmr [no modules matched] /home//.config/Slack/Cache/Cache_Data/index-dir/the-real-index +0ms vite:hmr [file change] /home//.config/google-chrome/Default/History-journal +0ms vite:hmr [no modules matched] /home//.config/google-chrome/Default/History-journal +0ms vite:hmr [file change] /home//.config/google-chrome/Default/History +0ms vite:hmr [no modules matched] /home//.config/google-chrome/Default/History +0ms vite:hmr [file change] /home//.config/Slack/logs/default/webapp-console.log +0ms vite:hmr [no modules matched] /home//.config/Slack/logs/default/webapp-console.log +0ms vite:hmr [file change] /home//.cache/JetBrains/WebStorm2023.1/log/indexing-diagnostic/.a20d561b/changed-files-pushing-events.json +0ms vite:hmr [no modules matched] /home//.cache/JetBrains/WebStorm2023.1/log/indexing-diagnostic/.a20d561b/changed-files-pushing-events.json +0ms vite:hmr [file change] /home//.cache/JetBrains/WebStorm2023.1/log/idea.log +0ms vite:hmr [no modules matched] /home//.cache/JetBrains/WebStorm2023.1/log/idea.log +0ms vite:hmr [file change] /home//.config/google-chrome/Default/Sync Data/LevelDB/000985.log +0ms vite:hmr [no modules matched] /home//.config/google-chrome/Default/Sync Data/LevelDB/000985.log + ```

Validations

github-actions[bot] commented 1 year ago

Hello @srflp. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

srflp commented 1 year ago

@Niputi I provided the reproduction and figured out that the problem is simpler to reproduce than I thought (which means the problem is quite severe)

dominikg commented 1 year ago

I can confirm that it breaks starting with vite-4.3.0-beta.3, 4.2.2 and 4.3.0-beta.2 don't have it.