Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug: File update consistently triggers 2 update events on Windows #193

Open
ghiscoding opened this issue Nov 15, 2024 · 5 comments
Open

Comments

@ghiscoding
Copy link

ghiscoding commented Nov 15, 2024

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)

Code_fOglgxJAgr

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 v3

@bpasero
Copy link
Contributor

bpasero commented Nov 15, 2024

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.

@ghiscoding
Copy link
Author

@bpasero ah yeah that's a good point, and yes I can still reproduce outside of VSCode

ApplicationFrameHost_dYxNGJQ8qt

@bpasero
Copy link
Contributor

bpasero commented Nov 15, 2024

👍 , 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.

@ghiscoding
Copy link
Author

ghiscoding commented Nov 15, 2024

maybe but in my case I had to use a Set to keep track of the files and wait about 150ms before calling the handler. The thing is that I had the same code in Chokidar v3 and didn't have any of these issues (but I didn't want to migrate to Chokidar v4). So seeing these duplicate events is a bit of a bummer when I know Chokidar worked fine and I wanted to give a chance to Parcel Watcher.

@ghiscoding
Copy link
Author

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants