Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tomastrajan opened this issue May 22, 2024 · 6 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime bug core: defer Issues related to @defer blocks. P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent workaround2: non-obvious
Milestone

Comments

@tomastrajan
Copy link
Contributor

tomastrajan commented May 22, 2024

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)

  1. open the provided Stackblitz

  2. open demo in separate tab (so it's easy to see network tab traffic without Stackblitz specific things)

  3. after 3 seconds, no additional bundle will be loaded after 3 seconds (network tab)

  4. remove the generic type from view child

  5. save and refresh the opened tab

  6. 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

https://stackblitz.com/edit/view-child-generic-arg-breaks-defer

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

@JeanMeche
Copy link
Member

JeanMeche commented May 22, 2024

Note that the issue also exist with the decorator query.
@ViewChild('test') child: Child breakes defer while @ViewChild('test') child: any doesn't present any issue.

@JeanMeche JeanMeche added area: core Issues related to the framework runtime core: queries core: defer Issues related to @defer blocks. labels May 22, 2024
@ngbot ngbot bot added this to the needsTriage milestone May 22, 2024
@tomastrajan
Copy link
Contributor Author

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
Copy link
Member

JoostK commented 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

import type { Child as ChildType } from './child.component';

so there isn't any need for an interface.

@JoostK
Copy link
Member

JoostK commented May 22, 2024

Or with a single import statement:

import { Child, type Child as ChildType } from './child.component';

also works.

@tomastrajan
Copy link
Contributor Author

Maybe this could be referenced in the docs as well ?

@JoostK JoostK added workaround1: obvious area: compiler Issues related to `ngc`, Angular's template compiler and removed workaround2: non-obvious core: queries labels May 22, 2024
@pkozlowski-opensource pkozlowski-opensource added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent bug labels May 22, 2024
@JeanMeche JeanMeche added workaround2: non-obvious and removed workaround1: obvious P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent bug labels May 22, 2024
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 22, 2024
@JeanMeche JeanMeche added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent bug labels May 22, 2024
@ngbot ngbot bot modified the milestones: needsTriage, Backlog May 22, 2024
@Pea1594

This comment was marked as off-topic.

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 area: core Issues related to the framework runtime bug core: defer Issues related to @defer blocks. P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent workaround2: non-obvious
Projects
None yet
Development

No branches or pull requests

6 participants