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

Structural directives not imported in standalone components don't break compilation #51861

Closed
aleesaan opened this issue Sep 22, 2023 · 8 comments

Comments

@aleesaan
Copy link
Contributor

aleesaan commented Sep 22, 2023

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

When I don't import a standalone component before using it, the compilation will break.
However, I can have non-imported structural directives in the template and the compilation will not break.

I noticed the following, which you can see in the reproduction repo I linked:

  • if the directive has no input, it just doesn’t render its host element;
  • if it has an input, it doesn’t render the host element and throws an error in the console;

I randomly noticed this during the migration to standalone, but it's quite an annoying bug as it can easily be missed, since the compilation doesn't break.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-structural-directive-repro?file=src%2Fapp.component.ts

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 16.2.2
Node: 18.17.1
Package Manager: npm 9.6.7
OS: darwin arm64
Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1602.2
@angular-devkit/build-angular   16.2.2
@angular-devkit/core            16.2.2
@angular-devkit/schematics      16.2.2
@angular/cli                    16.2.2
@schematics/angular             16.2.2
rxjs                            7.8.1
typescript                      5.1.6
zone.js                         0.13.3

Anything else?

No response

@pkozlowski-opensource
Copy link
Member

This is fundamentally the same issue as #46351

@aleesaan
Copy link
Contributor Author

Isn't it kind of different though? Structural directives starting with * could not be an unknown attribute, right?
We already get an error in the console when that directive has an input - couldn't we instead get the error during compilation?

@JeanMeche
Copy link
Member

I'd say It more related to #37322, @pkozlowski-opensource do you agree ?

@aleesaan
Copy link
Contributor Author

Yes that's exactly it @JeanMeche, I hadn't seen that issue before :)

@JeanMeche
Copy link
Member

I'll close this one as a dup then ! We can continue the discussion over there !

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2023
@pkozlowski-opensource
Copy link
Member

I'd say It more related to #37322, @pkozlowski-opensource do you agree ?

Yes and no :-)

Structural directives are just syntax sugar that resolves to directives being matched by attributes. The underlying issue is that our compiler can't detect missus of such directives since we don't know that those are directives.

We might be able to improve situation in #37322 but the fundamental problem is directive matching on attribute selectors.

@aleesaan
Copy link
Contributor Author

Thanks for the input all! Hopefully we can fix it 🤞

@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 Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants