From b62a2a62662a5e44e327487d636ef2f571471072 Mon Sep 17 00:00:00 2001 From: Gary Rennie Date: Thu, 17 Jul 2025 11:37:50 +0100 Subject: [PATCH] fix watchers never being cleaned up Previously, there was an issue, where a slow compilation could cause the watchers to build up and never be cleaned. This would result in both excessive logging and the compilation time increasing exponentially. This fix is a naive patch, simply locking if there is a build in progress, and unlocking when it completes. --- packages/@tailwindcss-cli/src/commands/build/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/@tailwindcss-cli/src/commands/build/index.ts b/packages/@tailwindcss-cli/src/commands/build/index.ts index 206bf27fbca2..56789155057d 100644 --- a/packages/@tailwindcss-cli/src/commands/build/index.ts +++ b/packages/@tailwindcss-cli/src/commands/build/index.ts @@ -237,16 +237,21 @@ export async function handle(args: Result>) { let [compiler, scanner] = await handleError(() => createCompiler(input, I)) + let lock = false + // Watch for changes if (args['--watch']) { let cleanupWatchers = await createWatchers( watchDirectories(scanner), async function handle(files) { try { + if (lock) return // If the only change happened to the output file, then we don't want to // trigger a rebuild because that will result in an infinite loop. if (files.length === 1 && files[0] === args['--output']) return + lock = true + using I = new Instrumentation() DEBUG && I.start('[@tailwindcss/cli] (watcher)') @@ -362,6 +367,7 @@ export async function handle(args: Result>) { eprintln(err.toString()) } } + lock = false }, )