Skip to content

fix(compiler-cli): clear un-fingerprinted preprocessor cache and lazy parser closures - #71930

Draft
mattrbeck wants to merge 1 commit into
angular:mainfrom
mattrbeck:fix/ngp-lazy-diag-cache-invalidation
Draft

mattrbeck wants to merge 1 commit into
angular:mainfrom
mattrbeck:fix/ngp-lazy-diag-cache-invalidation

Conversation

@mattrbeck

Copy link
Copy Markdown
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Follows up on #71904:

  1. In HybridCompiler.invalidateStaleFileAnalysis, moving existing.boundFingerprint = nextFingerprint outside the clearing if block while keeping existing.boundFingerprint !== undefined && existing.boundFingerprint !== nextFingerprint allows an un-fingerprinted fileCache entry (boundFingerprint === undefined, such as one populated by a direct processFileSync call) to be stamped with a valid boundFingerprint without clearing stale parsedTemplates, preparedTcbData, or tcb when a dependency's <ng-content> selectors change. Similarly, populateBoundData did not reset fileAnalysis.tcb, leaving stale TCB text for getTcbForFile when re-binding an un-fingerprinted entry.
  2. In parseComponentTemplate, the lazy diagNodes getter shared parseComponentTemplate's closure context, keeping the containing .ts file content, ComponentMetadata, and parse options alive on cached ParsedComponentTemplate entries even for external templates and even after diagNodes had already been evaluated.

Issue Number: N/A

What is the new behavior?

  1. HybridCompiler.invalidateStaleFileAnalysis compares existing.boundFingerprint !== nextFingerprint directly so transitioning from undefined to a computed fingerprint clears stale cached state before stamping nextFingerprint (while keeping (undefined, undefined) intact), and populateBoundData clears fileAnalysis.tcb = undefined whenever preparedTcbData is recomputed.
  2. parseComponentTemplate isolates the lazy diagNodes parser closures into createInlineDiagParser and createExternalDiagParser (avoiding capturing ComponentMetadata, and avoiding capturing .ts content for external/indirect templates) and defineLazyDiagNodes clears the parser closure reference once diagNodes is evaluated.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 10, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 10, 2026
… parser closures

Follows up on angular#71904 with two targeted hardening fixes:

1. In `HybridCompiler.invalidateStaleFileAnalysis`, drop the `existing.boundFingerprint !== undefined` guard when comparing `existing.boundFingerprint !== nextFingerprint` so un-fingerprinted cache entries (for example from a direct `processFileSync` call) clear stale `parsedTemplates`, `preparedTcbData`, and `tcb` before stamping a newly computed fingerprint. Also clear `fileAnalysis.tcb` in `populateBoundData` whenever `preparedTcbData` is recomputed so subsequent `getTcbForFile` lookups do not return stale TCB code.
2. In `parseComponentTemplate`, isolate the lazy `diagNodes` parser closures into `createInlineDiagParser` and `createExternalDiagParser` so external/indirect templates do not capture the containing TypeScript file's `content` or `ComponentMetadata`, and clear the parser closure reference inside `defineLazyDiagNodes` once `diagNodes` is evaluated.
@mattrbeck
mattrbeck force-pushed the fix/ngp-lazy-diag-cache-invalidation branch from 65d724c to 4eb2d46 Compare November 10, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant