Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
When using viewChild to query for a component wrapped with @defer and using the deferred component class as a generic type of the viewChild, eg child = viewChild<ChildComponent>('someTplVariable') the @defer behavior breaks and the deferred component bundle is not extracted as a lazy loaded bundle.
Steps to reproduce (also available inline in the Stackblitz)
-
open the provided Stackblitz
-
open demo in separate tab (so it's easy to see network tab traffic without Stackblitz specific things)
-
after 3 seconds, no additional bundle will be loaded after 3 seconds (network tab)
-
remove the generic type from view child
-
save and refresh the opened tab
-
the child bundle will be loaded after 3 seconds (network tab)
Expected behavior
Using the deferred component class only as a generic type will work with @defer
Please provide a link to a minimal reproduction of the bug
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version)
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 17.3.7
Node: 18.18.0
Package Manager: npm 10.2.3
OS: linux x64
Angular: 17.3.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1703.7
@angular-devkit/build-angular 17.3.7
@angular-devkit/core 17.3.7
@angular-devkit/schematics 17.3.7
@angular/cli 17.3.7
@schematics/angular 17.3.7
rxjs 7.8.1
typescript 5.3.3
Anything else?
No response
Activity
JeanMeche commentedon May 22, 2024
Note that the issue also exist with the decorator query.
@ViewChild('test') child: Childbreakes defer while@ViewChild('test') child: anydoesn't present any issue.tomastrajan commentedon May 22, 2024
The use-case is to be able to call the child components methods without a need to create additional interfaces to work around this issue. We use it a lot in this way in the custom component library.
JoostK commentedon May 22, 2024
I don't think the import removal analysis is capable of differentiating between type-position only imports.
You can get this to work using
so there isn't any need for an interface.
JoostK commentedon May 22, 2024
Or with a single import statement:
also works.
tomastrajan commentedon May 22, 2024
Maybe this could be referenced in the docs as well ?
17 remaining items
alxhub commentedon Aug 27, 2024
This does seem like something our logic could support easily enough...
fix(compiler-cli): defer symbols only used in types
fix(compiler-cli): defer symbols only used in types (#58104)
fix(compiler-cli): defer symbols only used in types (angular#58104)
angular-automatic-lock-bot commentedon Nov 7, 2024
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.