Skip to content

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Oct 7, 2024

Currently we don't defer any symbols that have references outside of the import statement and the imports array. This is a bit too aggressive, because it's possible that the symbol is only used for types (e.g. viewChild<SomeCmp>('ref')) which will be stripped when emitting to JS.

These changes expand the logic so that references inside type nodes aren't considered.

Note: one special case is when the symbol is used in constructor-based DI (e.g. constructor(someCmp: SomeCmp), because these constructors will be compiled to directiveInject calls. We don't need to worry about them, because the compiler introduces an additional import * as i1 from './some-cmp'; import that it uses to refer to the symbol.

Fixes #55991.

Currently we don't defer any symbols that have references outside of the `import` statement and the `imports` array. This is a bit too aggressive, because it's possible that the symbol is only used for types (e.g. `viewChild<SomeCmp>('ref')`) which will be stripped when emitting to JS.

These changes expand the logic so that references inside type nodes aren't considered.

**Note:** one special case is when the symbol used in constructor-based DI (e.g. `constructor(someCmp: SomeCmp)`, because these constructors will be compiled to `directiveInject` calls. We don't need to worry about them, because the compiler introduces an addition `import * as i1 from './some-cmp';` import that it uses to refer to the symbol.

Fixes angular#55991.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Oct 7, 2024
@ngbot ngbot bot modified the milestone: Backlog Oct 7, 2024
@angular-robot angular-robot bot removed the area: compiler Issues related to `ngc`, Angular's template compiler label Oct 7, 2024
@ngbot ngbot bot removed this from the Backlog milestone Oct 7, 2024
@crisbeto crisbeto requested a review from JoostK October 7, 2024 08:31
@crisbeto crisbeto marked this pull request as ready for review October 7, 2024 08:31
@tomastrajan
Copy link
Contributor

Thanks for the great fix!

@crisbeto crisbeto 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 Oct 7, 2024
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 8d8c03a.

The changes were merged into the following branches: main, 18.2.x

AndrewKushnir pushed a commit that referenced this pull request Oct 7, 2024
Currently we don't defer any symbols that have references outside of the `import` statement and the `imports` array. This is a bit too aggressive, because it's possible that the symbol is only used for types (e.g. `viewChild<SomeCmp>('ref')`) which will be stripped when emitting to JS.

These changes expand the logic so that references inside type nodes aren't considered.

**Note:** one special case is when the symbol used in constructor-based DI (e.g. `constructor(someCmp: SomeCmp)`, because these constructors will be compiled to `directiveInject` calls. We don't need to worry about them, because the compiler introduces an addition `import * as i1 from './some-cmp';` import that it uses to refer to the symbol.

Fixes #55991.

PR Close #58104
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Angular @defer breaks when a deferred component is used as a GENERIC TYPE (not a value) of the viewChild

4 participants