Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
7 tasks done
srflp opened this issue Apr 20, 2023 · 3 comments · Fixed by #12929
Labels
feat: hmr p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release

Comments

@srflp
Copy link

srflp commented Apr 20, 2023

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
  1. Enter this directory
cd ~/repro
  1. Create a sample project in this directory
pnpm create vite sample-project --template vanilla
  1. Enter the sample project folder
cd sample-project
  1. Install dependencies
pnpm i
  1. Run vite dev server in debug mode, to see files which are observed via HMR:
pnpm dev -d
  1. 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

  1. In another terminal, enter the ~/repro folder
cd ~/repro
  1. Create a file in this folder
touch hello_vite
  1. Modify this file:
vi hello_vite

(type in any characters and save using :wq)
12. 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
  vite:hmr [file change] /home/<redacted>/.java/.userPrefs/.userRootModFile.<redacted> +3s
  vite:hmr [no modules matched] /home/<redacted>/.java/.userPrefs/.userRootModFile.<redacted> +0ms
  vite:hmr [file change] /home/<redacted>/.config/google-chrome/Default/Network Action Predictor-journal +81ms
  vite:hmr [no modules matched] /home/<redacted>/.config/google-chrome/Default/Network Action Predictor-journal +0ms
  vite:hmr [file change] /home/<redacted>/.config/google-chrome/Default/Network Action Predictor +3ms
  vite:hmr [no modules matched] /home/<redacted>/.config/google-chrome/Default/Network Action Predictor +0ms
  vite:hmr [file change] /home/<redacted>/.config/google-chrome/Default/Preferences +5s
  vite:hmr [no modules matched] /home/<redacted>/.config/google-chrome/Default/Preferences +1ms
  vite:hmr [file change] /home/<redacted>/.config/Slack/Local Storage/leveldb/001872.log +0ms
  vite:hmr [no modules matched] /home/<redacted>/.config/Slack/Local Storage/leveldb/001872.log +0ms
  vite:hmr [file change] /home/<redacted>/.config/Slack/sentry/session.json +1ms
  vite:hmr [no modules matched] /home/<redacted>/.config/Slack/sentry/session.json +0ms
  vite:hmr [file change] /home/<redacted>/.config/Slack/Cache/Cache_Data/index-dir/the-real-index +0ms
  vite:hmr [no modules matched] /home/<redacted>/.config/Slack/Cache/Cache_Data/index-dir/the-real-index +0ms
  vite:hmr [file change] /home/<redacted>/.config/google-chrome/Default/History-journal +0ms
  vite:hmr [no modules matched] /home/<redacted>/.config/google-chrome/Default/History-journal +0ms
  vite:hmr [file change] /home/<redacted>/.config/google-chrome/Default/History +0ms
  vite:hmr [no modules matched] /home/<redacted>/.config/google-chrome/Default/History +0ms
  vite:hmr [file change] /home/<redacted>/.config/Slack/logs/default/webapp-console.log +0ms
  vite:hmr [no modules matched] /home/<redacted>/.config/Slack/logs/default/webapp-console.log +0ms
  vite:hmr [file change] /home/<redacted>/.cache/JetBrains/WebStorm2023.1/log/indexing-diagnostic/<redacted>.a20d561b/changed-files-pushing-events.json +0ms
  vite:hmr [no modules matched] /home/<redacted>/.cache/JetBrains/WebStorm2023.1/log/indexing-diagnostic/<redacted>.a20d561b/changed-files-pushing-events.json +0ms
  vite:hmr [file change] /home/<redacted>/.cache/JetBrains/WebStorm2023.1/log/idea.log +0ms
  vite:hmr [no modules matched] /home/<redacted>/.cache/JetBrains/WebStorm2023.1/log/idea.log +0ms
  vite:hmr [file change] /home/<redacted>/.config/google-chrome/Default/Sync Data/LevelDB/000985.log +0ms
  vite:hmr [no modules matched] /home/<redacted>/.config/google-chrome/Default/Sync Data/LevelDB/000985.log +

Validations

@srflp srflp changed the title Vite 4.3.0-beta.3, including 4.3.0 has broken HMR which watches user home directory Vite 4.3.0-beta.3, including 4.3.0 has broken HMR which watches user home directory, causing infinite reloads Apr 20, 2023
@Niputi Niputi added needs reproduction feat: hmr regression The issue only appears after a new release labels Apr 20, 2023
@github-actions
Copy link

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 srflp changed the title Vite 4.3.0-beta.3, including 4.3.0 has broken HMR which watches user home directory, causing infinite reloads Dev server in Vite 4.3.0-beta.3, including 4.3.0 allows to set HMR watcher to any folder on the disk via URI Apr 20, 2023
@srflp srflp changed the title Dev server in Vite 4.3.0-beta.3, including 4.3.0 allows to set HMR watcher to any folder on the disk via URI Dev server in Vite 4.3.0-beta.3, including 4.3.0 watches user's home folder instead of project files (in some particular case) Apr 20, 2023
@srflp srflp changed the title Dev server in Vite 4.3.0-beta.3, including 4.3.0 watches user's home folder instead of project files (in some particular case) 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) Apr 20, 2023
@srflp
Copy link
Author

srflp commented Apr 20, 2023

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

@srflp srflp changed the title 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) 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) Apr 20, 2023
@dominikg
Copy link
Contributor

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.

@dominikg dominikg added bug p4-important Violate documented behavior or significantly improves performance (priority) labels Apr 20, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: hmr p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants