chokidar
chokidar copied to clipboard
Events may be lost when Use in React + Electron + Webpack
Describe the bug
A clear and concise description of what the bug is.
Versions (please complete the following information):
- Chokidar version 3.5.2
- Node version v12.8.3
- OS version: MacOS 11.4
To Reproduce:
Steps to reproduce the behavior. Include filename and chokidar config.
Ideally prove a problem by isolating and making it reproducible with a very short sample program, which you could paste here:
const chokidar = require('chokidar');
const fs = require('fs');
// One-liner for files and directories starting with 'test'
chokidar.watch('test*', {})
.on('add', (event, path) => {
console.log(event, path);
})
.on("unlink", (event, path) => {
console.log(event, path)
});
fs.writeFileSync('test.txt', 'testing 1');
// In a comment describe expected output versus observed problem
The same code above, in React + Electron could be lost events, but in node it could not
Most valuable could be one or more test cases for test.js to demonstrate the problem.
Expected behavior A clear and concise description of what you expect to happen.
Additional context Add any other context about the problem here. Optionally nice to know what project you are working on.
i seem to run into similar issues above. is this ticket being investigated since it has been a full year since this ticket was last updated
i could provide more information on my end:
when I introduced 100ms delay between chokidar.watch using setTimeout and async await, then the file will not be missed.
It seems that when you add a watcher and then create a file immediately after too quickly, the event will always be lost in React+Electron environment.
And this also only shows up in electron+react and works normally in nodejs.
i initially suspect that there are hidden async call inside watcher setup codes that does not await properly. but if so then I don't know why it only shows in electron but not in nodejs.
Chokidar version 3.5.3 "electron": "^19.0.11", "react": "^18.1.0", macos: 12.3.1