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

addWatchFile can not be used to watch files outside of the module graph #7024

Closed
7 tasks done
zauni opened this issue Feb 21, 2022 · 4 comments · Fixed by #9723
Closed
7 tasks done

addWatchFile can not be used to watch files outside of the module graph #7024

zauni opened this issue Feb 21, 2022 · 4 comments · Fixed by #9723

Comments

@zauni
Copy link

zauni commented Feb 21, 2022

Describe the bug

When I am writing a plugin and using "addWatchFile" inside the plugin to watch files which are not imported in some JS file, then Vite is tracking that the file has changed, but doesn't reload because of the message "no modules matched"

For example I added some-other-file.yaml with "addWatchFile" and then Vite in debug mode logs this on changes:

vite:hmr [file change] some-other-file.yaml +42m
vite:hmr [no modules matched] some-other-file.yaml +1ms

In the reproduction you have to do npm run dev and then change the file some-other-file.yaml to see this output.

If I do this in rollup, it is doing the reload on file changes. But Vite is somewhere loosing the info of the file path inside the module graph.

This was noticed when developing the rollup-plugin-openapi

Reproduction

https://stackblitz.com/edit/vitejs-vite-wuaaxt?file=vite.config.js

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 68.09 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/Library/Caches/fnm_multishells/14259_1645436772510/bin/node
    npm: 8.3.1 - ~/Library/Caches/fnm_multishells/14259_1645436772510/bin/npm
  Browsers:
    Chrome: 98.0.4758.102
    Firefox: 97.0
    Firefox Developer Edition: 98.0
    Safari: 15.3
npmPackages:
    vite: ^2.7.2 => 2.8.4 

Used Package Manager

npm

Logs

vite:hmr [file change] some-other-file.yaml +42m
vite:hmr [no modules matched] some-other-file.yaml +1ms

Validations

@jplhomer
Copy link
Contributor

jplhomer commented Mar 8, 2022

I assume the expectation here is to force a full page reload, yeah?

@zauni
Copy link
Author

zauni commented Mar 8, 2022

@jplhomer Yes that would be the expectation. I don't think that HMR is possible in this case or even makes sense because the user wants to add arbitrary files to the watcher with the addWatchFile method. Or that is how I understand the use case of this method.

zauni added a commit to zauni/rollup-plugin-openapi that referenced this issue May 17, 2022
@zauni
Copy link
Author

zauni commented May 17, 2022

@jplhomer I was able to workaround the issue by adding a hook for handleHotUpdate and invalidating the root YAML file when a referenced YAML file was changed. And then I can send a full-reload command to the WebSocket server and everything works as expected.

@see zauni/rollup-plugin-openapi@4a2b480

Should I leave the issue open to address the underlying problem with addWatchFile or should I close it because a workaround exists?

@jplhomer
Copy link
Contributor

Seems like the underlying problem should still be addressed 👍

patak-dev pushed a commit that referenced this issue Nov 16, 2022
Co-authored-by: Matt Jones <mattjones701@gmail.com>
fc pushed a commit to fc/vite that referenced this issue Nov 23, 2022
Co-authored-by: Matt Jones <mattjones701@gmail.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants