Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Emulated view encapsulation incorrectly transforms CSS that uses :is() or :where() #45686

Copy link
Copy link
@ChrisTM

Description

@ChrisTM
Issue body actions

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

https://stackblitz.com/edit/angular-ivy-yc96o6?file=src/app/app.component.css

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

Reactions are currently unavailable

Metadata

Metadata

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerarea: coreIssues related to the framework runtimeIssues related to the framework runtimebugcore: CSS encapsulationstate: has PR

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.