From fbc88fd83cab5d5cc92fd3869a8201ddb436c41c Mon Sep 17 00:00:00 2001 From: Tung Vu Date: Mon, 11 Sep 2017 00:04:35 +0700 Subject: [PATCH] fix: remove watcher.close and use watcher.once calling chokidar's `watch()` on a same file multiple times doesn't necessarily create multiple background watchers. These calls and `watcher.close()` calls might cause a race-condition bug that stops the seemingly newly created watcher. this fix will not remove the need to use debounce because we need to make sure multiple file changes happen simultaneously (usually due to a build pipeline) will not result in an inconsistent state. --- lib/listening.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/listening.js b/lib/listening.js index 3b68262..b6762fe 100644 --- a/lib/listening.js +++ b/lib/listening.js @@ -36,9 +36,6 @@ const restartServer = (file, flags, watcher) => { } } - // Stop watching any files - watcher.close() - // Remove file that changed from the `require` cache for (const item of toDelete) { let location @@ -102,7 +99,7 @@ module.exports = async (server, inUse, flags, sockets) => { const watcher = watch(toWatch, watchConfig) // Ensure that the server gets restarted if a file changes - watcher.on( + watcher.once( 'all', debounce((event, filePath) => { const location = path.relative(process.cwd(), filePath)