Skip to content

fix(@angular/build): scope BundlerContext invalidation and error watch files - #34429

Draft
alan-agius4 wants to merge 2 commits into
angular:mainfrom
alan-agius4:fix/bundler-context-invalidation
Draft

alan-agius4 wants to merge 2 commits into
angular:mainfrom
alan-agius4:fix/bundler-context-invalidation

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  1. Scope BundlerContext.invalidate() to this.watchFiles:
    • When multiple BundlerContext instances share a MemoryLoadResultCache (such as all component stylesheet contexts in ComponentStylesheetBundler), this.#loadCache.invalidate(file) returns true for any file present in the shared cache regardless of whether the current BundlerContext ever loaded it.
    • Ensure this.#loadCache.invalidate(file) is still invoked for changed files, but only mark the BundlerContext as invalid (and clear this.#esbuildResult) when a changed file is present in this.watchFiles.
  2. Scope failure watchFiles tracking and preserve transitive CSS error recovery:
    • Lazily track keys accessed via this.#loadCache per incremental BundlerContext (this.#loadCacheKeys) so #addLoadCacheFilesToWatch() only adds watch files for keys loaded by that context rather than copying all components' watch files from the shared cache.
    • Retain existing this.watchFiles across failed rebuilds (only clearing on successful builds) and ensure non-internal entry points, error/note locations, and unresolved relative imports are added to this.watchFiles on BuildFailure.

ngwr Benchmark Results

Metric main Branch Delta
Runs (ms) 11953, 11735, 11952, 11871, 12022 11939, 11802, 11807, 11531, 11517
Median (ms) 11952 ms 11802 ms -1.26%
Mean (ms) 11907 ms 11719 ms -1.58%
Min (ms) 11735 ms 11517 ms -1.86%

…shot bundle results

Ensure `BundlerContext.invalidate()` only clears `#esbuildResult` when a changed file is in `this.watchFiles` while still invalidating `#loadCache`, preventing edits to one component stylesheet from invalidating all other components sharing the same `MemoryLoadResultCache`.

Also scope `#addLoadCacheFilesToWatch()` to the load cache keys accessed by the current `BundlerContext`, retain `watchFiles` across failed rebuilds while tracking entry points and unresolved relative imports on build failures, and cache `#esbuildResult` in non-incremental builds so multiple components sharing the same `styleUrl` do not re-run esbuild.
@alan-agius4 alan-agius4 changed the title fix(@angular/build): scope BundlerContext invalidation and cache one-shot bundle results fix(@angular/build): scope BundlerContext invalidation and watch files Oct 20, 2026
@alan-agius4 alan-agius4 changed the title fix(@angular/build): scope BundlerContext invalidation and watch files fix(@angular/build): scope BundlerContext invalidation and error watch files Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant