From 8be7e567e5954ee8910160bbde9df313fd0a81ac Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sun, 26 Apr 2026 19:05:05 +0200 Subject: [PATCH] fix: Avoid auto-reload for recently created source directory Watchpack has a bug that caused it to dispatch change events for files that were created recently (up to 2 seconds before now). This can trigger an unwanted auto-reload, e.g. in the scenario of an extension developer building an extension and using `web-ext run` to immediately launch that built package. Fixing this bug caused test.cli.run-target-chromium.js to time out because the "with auto-reload" test got stuck, because it waited until "The extension will reload if any source file changes" was logged before writing a file to trigger auto-reload, but that message was logged before the watcher was registered. To fix that test issue, move the logging after initializing the reload strategy. --- src/cmd/run.js | 4 ++-- src/watcher.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cmd/run.js b/src/cmd/run.js index d95b32168a..fbbfffb555 100644 --- a/src/cmd/run.js +++ b/src/cmd/run.js @@ -206,8 +206,6 @@ export default async function run( if (noReload) { log.info('Automatic extension reloading has been disabled'); } else { - log.info('The extension will reload if any source file changes'); - reloadStrategy({ extensionRunner, sourceDir, @@ -217,6 +215,8 @@ export default async function run( ignoreFiles, noInput, }); + + log.info('The extension will reload if any source file changes'); } return extensionRunner; diff --git a/src/watcher.js b/src/watcher.js index d4a784b474..c2e4bde76a 100644 --- a/src/watcher.js +++ b/src/watcher.js @@ -63,7 +63,9 @@ export default function onSourceChange({ files: watchedFiles, directories: watchedDirs, missing: [], - startTime: Date.now(), + // startTime: Date.now(), is explicitly NOT set because it causes onChange + // to be emitted if the files were created shortly before now! + // See https://github.com/webpack/watchpack/issues/295 }); // TODO: support interrupting the watcher on Windows.