fix(compiler-cli): report NG8030 when a class-based query predicate blocks deferred lazy loading#69503
Draft
arturovt wants to merge 1 commit into
Draft
fix(compiler-cli): report NG8030 when a class-based query predicate blocks deferred lazy loading#69503arturovt wants to merge 1 commit into
arturovt wants to merge 1 commit into
Conversation
Contributor
Author
|
@JeanMeche as discussed internally |
…locks deferred lazy loading When a component is placed exclusively inside a @defer block, Angular can split it into a separate lazy chunk. That optimization silently breaks if the same component is also used as a viewChild or contentChild predicate — the class reference in the query keeps the import eager, so the bundler never gets a chance to defer it. This commit introduces error NG8030 (DEFERRED_COMPONENT_USED_IN_QUERY) that fires whenever the compiler detects this pattern during the resolve phase. The diagnostic points directly at the predicate expression and suggests the string-based alternative with a local template reference variable. The check lives in the component handler's resolve phase rather than in packages/.../typecheck/extended/checks because it needs to cross-reference two pieces of data that only come together there: the deferred-per-block dependency map (which components are exclusively behind @defer) and the eagerlyUsedDecls set (which components are also used outside @defer, so they're already eager and there's nothing to warn about). The extendedTemplateCheck interface doesn't have access to either — it only sees the template AST and a type-check context. The eagerlyUsedDecls guard is important: if a component appears both inside and outside a @defer block, the import is already eager regardless of the query, so no diagnostic is emitted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a component is placed exclusively inside a @defer block, Angular can split it into a separate lazy chunk. That optimization silently breaks if the same component is also used as a viewChild or contentChild predicate — the class reference in the query keeps the import eager, so the bundler never gets a chance to defer it.
This commit introduces error NG8030 (DEFERRED_COMPONENT_USED_IN_QUERY) that fires whenever the compiler detects this pattern during the resolve phase. The diagnostic points directly at the predicate expression and suggests the string-based alternative with a local template reference variable.
The check lives in the component handler's resolve phase rather than in packages/.../typecheck/extended/checks because it needs to cross-reference two pieces of data that only come together there: the deferred-per-block dependency map (which components are exclusively behind @defer) and the eagerlyUsedDecls set (which components are also used outside @defer, so they're already eager and there's nothing to warn about). The extendedTemplateCheck interface doesn't have access to either — it only sees the template AST and a type-check context.
The eagerlyUsedDecls guard is important: if a component appears both inside and outside a @defer block, the import is already eager regardless of the query, so no diagnostic is emitted.