Repository navigation
Description
Which @angular/* package(s) are the source of the bug?
compiler, Don't known / other
Is this a regression?
No
Description
When using emulated view encapsulation, component CSS that uses the :is or :where pseudo class selector functions gets compiled incorrectly.
Example 1
Consider the following 2 selectors, which differ only in the number of items inside of :is:
:is(.foo) {}
:is(.foo, .bar, .baz) {}I expected each item in the :is selector list to be transformed the same, but the first and last items are treated differently from the middle items. This is the compiled result:
[_ngcontent-uly-c97]:is(.foo) {}
[_ngcontent-uly-c97]:is(.foo, .bar[_ngcontent-uly-c97], .baz)[_ngcontent-uly-c97] {}Example 2
When used before or after :host, the number of items inside of :is unexpectedly affects the presence of an [_ngcontent] qualifier outside of :is. The qualifier is missing for 1 item, but added for >1 item. This component CSS:
:is(.foo) :host {}
:is(.foo, .bar) :host {}
:host :is(.foo) {}
:host :is(.foo, .bar) {}Compiles to:
:is(.foo) [_nghost-kfp-c134] {}
[_ngcontent-kfp-c134]:is(.foo, .bar) [_nghost-kfp-c134] {}
[_nghost-kfp-c134] [_ngcontent-kfp-c134]:is(.foo) {}
[_nghost-kfp-c134] [_ngcontent-kfp-c134]:is(.foo, .bar)[_ngcontent-kfp-c134] {}Reproduction
https://stackblitz.com/edit/angular-ivy-yc96o6?file=src/app/app.component.css demonstrates a live reproduction of this issue.
For my specific use case, I had a selector that looked like:is(a, b, c) :host. I was able to work around the problem by rewriting it to either of :host-context(a, b, c) :host or a :host, b :host, c :host (both compile to the same output). But in general, using :is and :where seems either unsupported or broken. If it's unsupported, I think it would be helpful if the compiler threw an error because the current behavior is hard to predict and does not seem useful.
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)
I'm not using `ng`, so I can't provide `ng version` output. But the reproduction in StackBlitz is using @angular/* packages at version 13.3.3.
Anything else?
No response
Activity
dario-piotrowicz commentedon Apr 27, 2022
good catch @ChrisTM 🙂 , I've found the bug causing this issue, it does look pretty small and easy to fix
I've practically solved it, I need to check things, add unit tests and open a PR, I should hopefully be able to do it in the next few days 🙂👍
(@dylhunn , @JoostK if either of you could assign me to this issue that'd be awesome 🙏 🙂 🙇)
dario-piotrowicz commentedon Apr 27, 2022
Thanks @JoostK! 😃
19 remaining items
montella1507 commentedon Nov 15, 2023
however.. i dont think it solved my prpoblem
montella1507 commentedon Nov 15, 2023
montella1507 commentedon Nov 16, 2023
But you are close
:-)
Generated from your code (not working - misaligned whitespace):
:is(.dark )[_nghost-hvk-c87]Working:
:is(.dark) [_nghost-hvk-c87]JeanMeche commentedon Dec 8, 2023
@montella1507 Can you check with the change I just made in #49169. It should fix your issue !
fix(compiler): transform pseudo selectors correctly for the encapsula…
fix(compiler): transform pseudo selectors correctly for the encapsula…
fix(compiler): transform pseudo selectors correctly for the encapsula…
angular-automatic-lock-bot commentedon Nov 10, 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.