Skip to content

fix(@angular/build): deduplicate spurious chokidar polling change events - #34188

Closed
alan-agius4 wants to merge 3 commits into
angular:mainfrom
alan-agius4:fix/inline-style-language-flaky
Closed

alan-agius4 wants to merge 3 commits into
angular:mainfrom
alan-agius4:fix/inline-style-language-flaky

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

When using Chokidar in polling mode, non-atomic file writes (such as open with O_TRUNC followed by write) can span across poll intervals and cause Chokidar to emit two 'change' events for a single file modification. If the initial rebuild completes quickly (e.g. in JIT mode), the trailing poll event can flush a second rebuild batch with the same file state.

Track the last known mtimeMs and size of watched files in createChokidarWatcher and ignore 'modified' events when the file's mtimeMs and size have not changed since the previous queued or flushed event.

@alan-agius4
alan-agius4 marked this pull request as ready for review September 28, 2026 11:01
@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 28, 2026

@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 introduces a fileStats map to track the modification times and sizes of watched files, helping to prevent redundant change events when no actual modifications have occurred. The review feedback highlights a performance concern where synchronous file system operations (fs.statSync) are used inside the asynchronous next() method, which could block the Node.js event loop when processing many files. It is recommended to use asynchronous operations with Promise.all instead.

Comment thread packages/angular/build/src/utils/watcher.ts
@alan-agius4
alan-agius4 force-pushed the fix/inline-style-language-flaky branch from d040364 to 217669f Compare September 28, 2026 11:42
When using Chokidar in polling mode, non-atomic file writes (such as open with O_TRUNC followed by write) can span across poll intervals and cause Chokidar to emit two 'change' events for a single file modification. If the initial rebuild completes quickly (e.g. in JIT mode), the trailing poll event can flush a second rebuild batch with the same file state.

Track the last known mtimeMs and size of watched files in createChokidarWatcher and ignore 'modified' events when the file's mtimeMs and size have not changed since the previous queued or flushed event.
@alan-agius4
alan-agius4 force-pushed the fix/inline-style-language-flaky branch from 217669f to ae097a0 Compare September 28, 2026 11:47
@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 28, 2026
@clydin

clydin commented Sep 28, 2026

Copy link
Copy Markdown
Member

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

@clydin clydin closed this in 3680773 Sep 28, 2026
clydin pushed a commit that referenced this pull request Sep 28, 2026
…nts (#34188)

When using Chokidar in polling mode, non-atomic file writes (such as open with O_TRUNC followed by write) can span across poll intervals and cause Chokidar to emit two 'change' events for a single file modification. If the initial rebuild completes quickly (e.g. in JIT mode), the trailing poll event can flush a second rebuild batch with the same file state.

Track the last known mtimeMs and size of watched files in createChokidarWatcher and ignore 'modified' events when the file's mtimeMs and size have not changed since the previous queued or flushed event.

PR Close #34188
clydin pushed a commit that referenced this pull request Sep 28, 2026
angular-robot pushed a commit to angular-robot/angular-cli that referenced this pull request Sep 28, 2026
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: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants