Skip to content

fix(@angular/build): ensure chokidar watcher is ready before returning - #34122

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:fix-build-watcher-chokidar-ready
Sep 18, 2026
Merged

alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:fix-build-watcher-chokidar-ready

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

When initializing chokidar.watch with ignoreInitial: true, files visited during the initial scan are treated as the initial baseline and do not emit change events. If createChokidarWatcher returns before the initial scan completes, subsequent file modifications made shortly after setup can be visited for the first time during the initial scan, causing the change event to be dropped.

Awaiting the ready event ensures the watcher's initial scan is completed and the watcher is actively listening before returning. This resolves test flakiness in rebuild error detection tests where files are modified immediately after the initial build.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes explicit timeouts from the dev-server build-errors test and updates the esbuild watcher initialization to await the 'ready' or 'error' events before returning. Feedback on the changes highlights a potential event listener leak in the watcher's promise implementation, suggesting that both 'ready' and 'error' listeners should be cleaned up once the promise settles.

Comment thread packages/angular/build/src/tools/esbuild/watcher.ts Outdated
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Sep 18, 2026
@alan-agius4
alan-agius4 requested a review from clydin September 18, 2026 15:58
When initializing chokidar.watch with ignoreInitial: true, files visited during the initial scan are treated as the initial baseline and do not emit change events. If createChokidarWatcher returns before the initial scan completes, subsequent file modifications made shortly after setup can be visited for the first time during the initial scan, causing the change event to be dropped.

Awaiting the ready event ensures the watcher's initial scan is completed and the watcher is actively listening before returning. This resolves test flakiness in rebuild error detection tests where files are modified immediately after the initial build.
@alan-agius4 alan-agius4 added target: rc This PR is targeted for the next release-candidate and removed target: patch This PR is targeted for the next patch release labels Sep 18, 2026
@alan-agius4
alan-agius4 force-pushed the fix-build-watcher-chokidar-ready branch from 23d0e67 to f22bff9 Compare September 18, 2026 16:00
Comment thread packages/angular/build/src/tools/esbuild/watcher.ts Outdated
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 18, 2026
@alan-agius4
alan-agius4 merged commit dc79270 into angular:main Sep 18, 2026
39 checks passed
@alan-agius4
alan-agius4 deleted the fix-build-watcher-chokidar-ready branch September 18, 2026 16:36
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants