-
Notifications
You must be signed in to change notification settings - Fork 46
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
Bug: File update consistently triggers 2 update events on Windows #193
Comments
When reproducing issues like these, I would suggest to be as close to the file system as possible, for example by testing with node.js directly and not VS Code. I recently pushed microsoft/vscode#231542 which separated a truncate of a file from a write to the file using VS Code on Windows, so its possible you see 2 events because of that rather unexpected file write behaviour in VS Code. |
@bpasero ah yeah that's a good point, and yes I can still reproduce outside of VSCode |
👍 , it is possible that this is just how the underlying OS watcher behaves, maybe because 1 event is emitted for the truncating and 1 for the writing. What we do in our app is to normalise all events we get over a duration of some millies and thus remove duplicates. |
maybe but in my case I had to use a |
Also I don't have any other platforms to test this with, but it would be great if someone can clone the small repo I created and test it out on platform other than Windows and report back. Thanks https://github.com/ghiscoding/parcel-watcher-issue |
On Windows (the only environment I can test with), watching files will consistently trigger 2 update events whenever any files are updated. The issue is very consistent and will always trigger 2 update events whenever a file (or multiple files) is updated, for every file 2 events will be sent
Repro
I created a small GitHub project as a full repro, you can follow the steps shown on the small project readme
https://github.com/ghiscoding/parcel-watcher-issue
Demo
Below is a demo of the issue, doing a file save triggers 2 update events consistently on Windows platform (I'm not sure if this happens on other platforms, possibly not)
Alternative
For now the only way that I found to avoid rebuilding the same file(s) multiple times is to use a
Set
and add a delay of 150ms before calling the callback handler. It's a bit annoying to have to wait 150ms before calling the handler when I barely had to wait when I had the same code using Chokidar v3The text was updated successfully, but these errors were encountered: