Event throttling discards updates
We are using chokidar for a custom build pipeline and if we switch branches, it sometimes happens that a file is changed multiple times within 50ms. Because of the throttling introduced in https://github.com/paulmillr/chokidar/commit/b4e9430ef8932f8d6ef4ab2468b2bd1e1bbb5d6d we only get the first of these changes and no final event, and thus our build output is wrong, because we act on outdated information and do not get a later signal again. I would expect a final event when the throttling interval has passed.
Removing the block: https://github.com/paulmillr/chokidar/blob/main/src/index.ts#L657 fixed it for us.
Could you please clarify what this codepath is actually used for?
Describe the bug
A clear and concise description of what the bug is.
Versions (please complete the following information):
- Chokidar version: 5.0.0
- Node version: v24.14.1
- OS version: MacOS 26.4
To Reproduce:
diff --git a/src/index.test.ts b/src/index.test.ts
index 453e1c6..c608a71 100644
--- a/src/index.test.ts
+++ b/src/index.test.ts
@@ -432,6 +432,18 @@ const runTests = (baseopts: chokidar.ChokidarOptions) => {
ok(rawSpy.called);
equal(spy.callCount, 1);
});
+ it('should emit two `change` events for two writes within 50ms', async () => {
+ const testPath = dpath('change.txt');
+ const spy = createSpy<EmitArgs, void>(function quickChangeSpy() {});
+ watcher.on(EV.CHANGE, spy);
+
+ await write(testPath, time());
+ await delay(25);
+ await write(testPath, time());
+
+ await waitFor([[spy, 2, [testPath]]]);
+ ok(getCallsWith(spy, [testPath]).length >= 2);
+ });
it('should emit `unlink` event when file was removed', async () => {
const testPath = dpath('unlink.txt');
const spy = createSpy<EmitArgs, void>(function unlinkSpy() {});Expected behavior I would expect that after the throttle period has passed, at least one more change event would be triggered, if any change events occureed during the throttle period.
Source: paulmillr/chokidar