Skip to content

fix(compiler): scope nested CSS rules#50693

Closed
crisbeto wants to merge 1 commit into
angular:mainfrom
crisbeto:nested-css-encapsulation
Closed

fix(compiler): scope nested CSS rules#50693
crisbeto wants to merge 1 commit into
angular:mainfrom
crisbeto:nested-css-encapsulation

Conversation

@crisbeto

Copy link
Copy Markdown
Member

Browsers now support nesting CSS rules however our emulated encapsulation wasn't processing rules nested inside of other rules, except for at-rules.

These changes update the encapsulation logic to process rules inside of other rules. I also had to fix a couple of additional bugs where we didn't handle the ampersand symbol in a selector correctly and we weren't skipping style blocks inside of strings.

@crisbeto crisbeto Jun 13, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the context of this assertion, however this is actually invalid syntax (note the mismatching quotes). I had to update the test, because after my changes, invalid syntax would prevent styles from being encapsulated correctly.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Jun 13, 2023
@ngbot ngbot Bot modified the milestone: Backlog Jun 13, 2023
@crisbeto
crisbeto marked this pull request as ready for review June 13, 2023 10:43
@crisbeto
crisbeto requested review from jessicajaniuk and pkozlowski-opensource and removed request for jessicajaniuk June 13, 2023 10:46
Comment thread packages/compiler/src/shadow_css.ts Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context behind the isBlock flag is that as the way the parser is set up right now, it doesn't distinguish between something like color: red as a CSS property and color:red as a selector. Until now it wasn't a problem since we didn't scope anything inside of other rules (except for @media, @container etc).

@pkozlowski-opensource pkozlowski-opensource added the action: global presubmit The PR is in need of a google3 global presubmit label Jul 4, 2023
@pkozlowski-opensource

Copy link
Copy Markdown
Member

@crisbeto this change looks reasonable to me. As discussed yesterday, we should run TGP on it.

I also wonder if you want to have another pair of eyes on this PR, from someone more familiar with the CSS syntax / this parser bit.

@crisbeto

crisbeto commented Jul 5, 2023

Copy link
Copy Markdown
Member Author

The TGP showed one legit failure in a file with a bunch of base64-encoded images. I'll have to investigate deeper.

@crisbeto crisbeto added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 5, 2023
[Browsers now support nesting CSS rules](https://developer.chrome.com/articles/css-nesting/) however our emulated encapsulation wasn't processing rules nested inside of other rules, except for at-rules.

These changes update the encapsulation logic to process rules inside of other rules. I also had to fix a couple of additional bugs where we didn't handle the ampersand symbol in a selector correctly and we weren't skipping style blocks inside of strings.
@crisbeto
crisbeto force-pushed the nested-css-encapsulation branch from c7164a9 to 1deec7d Compare September 19, 2024 13:19
@angular-robot angular-robot Bot added area: compiler Issues related to `ngc`, Angular's template compiler and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Sep 19, 2024
@thePunderWoman thePunderWoman added state: blocked and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 22, 2024
@crisbeto crisbeto closed this Jun 4, 2025
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: global presubmit The PR is in need of a google3 global presubmit area: compiler Issues related to `ngc`, Angular's template compiler state: blocked target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants