Skip to content

fix(@angular/build): retain watch files on error in load result cache - #33752

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix/postcss-watch-error-caching
Aug 5, 2026
Merged

fix(@angular/build): retain watch files on error in load result cache#33752
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:fix/postcss-watch-error-caching

Conversation

@clydin

@clydin clydin commented Aug 4, 2026

Copy link
Copy Markdown
Member

During incremental builds (serve and build --watch), caching an error result that lacks watch files would cause previously tracked dependency files to be dropped from the file watcher dependency map. For PostCSS plugins that read external dependency files (such as Tailwind configs or theme files), a syntax or parse error in a dependency file would result in an error being cached without watch files, preventing any subsequent edits to the dependency file from clearing the error until the entry stylesheet itself was modified.

This commit improves MemoryLoadResultCache to remember the last-known watch set for each cache key across invalidations and union it into any newly cached error result. Additionally, compileString() in stylesheet-plugin-factory now explicitly returns error.file in watchFiles when catching a PostCSS CssSyntaxError, mirroring Sass and Less behavior.

Closes #33666

@clydin clydin added the target: patch This PR is targeted for the next patch release label Aug 4, 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 updates the MemoryLoadResultCache to preserve and track previous watch files when caching build results that contain errors, ensuring that file dependencies are still watched and rebuilt correctly after a build failure. It also adds comprehensive tests for this behavior and updates the stylesheet plugin factory to include watchFiles in error results. The review feedback suggests copying the watchFiles array to prevent side effects from subsequent mutations and avoiding duplicate entries in the watchFiles array when the error file is the same as the entry filename.

Comment thread packages/angular/build/src/tools/esbuild/load-result-cache.ts Outdated
Comment thread packages/angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts Outdated
During incremental builds (serve and build --watch), caching an error result that lacks watch files would cause previously tracked dependency files to be dropped from the file watcher dependency map. For PostCSS plugins that read external dependency files (such as Tailwind configs or theme files), a syntax or parse error in a dependency file would result in an error being cached without watch files, preventing any subsequent edits to the dependency file from clearing the error until the entry stylesheet itself was modified.

This commit improves MemoryLoadResultCache to remember the last-known watch set for each cache key across invalidations and union it into any newly cached error result. Additionally, compileString() in stylesheet-plugin-factory now explicitly returns error.file in watchFiles when catching a PostCSS CssSyntaxError, mirroring Sass and Less behavior.

Closes angular#33666
@clydin
clydin force-pushed the fix/postcss-watch-error-caching branch from b08a6c0 to 866184c Compare August 4, 2026 22:58
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 4, 2026
@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 Aug 5, 2026
@alan-agius4
alan-agius4 merged commit bcadbbe into angular:main Aug 5, 2026
40 of 41 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

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

@clydin
clydin deleted the fix/postcss-watch-error-caching branch August 5, 2026 12:41
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

2 participants