Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(compiler): fix pseudo-selector parsing issues #58557

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

Conversation

GeorgySerga
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

Issue Number: #58226

What is the new behavior?

:where and :is with attached selectors of other types are parsed as all other selectors. If selectors consist only of those two than each of them is scoped separately (recursively) and result is returned back

Does this PR introduce a breaking change?

  • Yes
  • No (some selectors may be evaluated differently)

Other information

fix several use-cases where `:host` was used in or around pseudo-selectors
- `:host` followed by a comma inside pseudo-selectors
- `:host` outside of pseudo-selectors when another `:host` is present within
see tests for examples
fix transformation logic for `:where` and `:is` pseudo-selectors
when these selectors were used in a chain. results were often broken,
the last letter of the selector was incorrectly trimmed.
see tests for examples

Fixes angular#58226
@pullapprove pullapprove bot requested a review from JoostK November 8, 2024 00:05
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 8, 2024
@ngbot ngbot bot added this to the Backlog milestone Nov 8, 2024
@JeanMeche JeanMeche added the target: rc This PR is targeted for the next release-candidate label Nov 8, 2024
@JeanMeche JeanMeche modified the milestones: Backlog, v19 final Nov 8, 2024
fix results which had to parse several `-shadowcsshost-no-combinator` occurrences in a single selector
@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 Nov 8, 2024
multiline selectors where not correctly recognized by the regexp, fix it to fetch newlines as well

Fixes angular#58399
@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 Nov 8, 2024
@ngbot ngbot bot modified the milestones: v19 final, Backlog Nov 8, 2024
@GeorgySerga
Copy link
Contributor Author

Passed TGP

@LeonEck
Copy link

LeonEck commented Nov 13, 2024

@GeorgySerga I tested your change and the first regression that I reported in #58226 is still present.

Given this code:

:host {
  &:not(&.foo, &.bar) {
    color: red;
  }
}

It produces the following in your PR:

[_nghost-%COMP%]:not([_nghost-%COMP%].foo,.bar[_nghost-%COMP%]){color:red}

It previously produced this:

[_nghost-%COMP%]:not([_nghost-%COMP%] .foo, .bar)[_nghost-%COMP%]{color:red}

Since the changes in 18.2.8 have only been reverted on the 18 branch and not for 19, we would currently see the same regression again. I noticed that you added a test for this case. Is the new output now the one you consider correct? Is this change now intentional? In which case this should be marked and documented as a breaking change.

@JeanMeche
Copy link
Member

@LeonEck fwiw, the breaking change window for v19 is now closed. Either we're able to land a non-breaking fix or this fix will also be reverted in v19 (until a non-breaking one can land).

@GeorgySerga
Copy link
Contributor Author

Hi @LeonEck , thank you! I don't think I quite understand the example you shared. If I understand correctly

:host {
  &:not(&.foo, &.bar) {
    color: red;
  }
}

should be (after sass conversion)

:host:not(:host.foo, :host.bar)

(a host element, which is not a host with class .foo or host with class .bar) and therefore converted to what you shared [_nghost-%COMP%]:not([_nghost-%COMP%].foo,.bar[_nghost-%COMP%]){color:red} by Angular.

Could you please share more? Thanks!

@GeorgySerga
Copy link
Contributor Author

GeorgySerga commented Nov 13, 2024

I added several variations of those selectors into the tests here as well, so you can take a look: https://github.com/angular/angular/pull/58557/files#diff-874bc712ebc9efc52417f6e744bd2b118514d58405dd2c31df0ae467ff297840R86-R100 .

@LeonEck
Copy link

LeonEck commented Nov 13, 2024

@GeorgySerga I think the [_nghost-%COMP%] that directly follows the .bar could be the issue why it isn‘t working anymore. But my main concern is that we have code that relies on the current output. So any change, even a change that might make it more correct, I beliefe should be treated as a breaking change, given that the current behavior was like that for years.
To us this is especially a concern since we are publishing a library. So without us changing anything, users that update to Angular 19 would see broken styles. And even if we wanted to prepare a fix beforehand, given that Angular 19 is expected in a week, we would need to know the compiler behavior asap.
I would like to see the same revert done in 69dce38 on the Angular 19 branch so that behavior doesn’t change for now. And after Angular 19 is released there is more time to look into this and decide what output the compiler should produce.

@GeorgySerga
Copy link
Contributor Author

Thank you @LeonEck ! Addressing this part

I think the [_nghost-%COMP%] that directly follows the .bar could be the issue why it isn‘t working anymore.

Styles apply regardless of order in this case .class[attribute] or [attribute].class
https://jsbin.com/rebudibeze/edit?html,css,output

@LeonEck
Copy link

LeonEck commented Nov 14, 2024

I edited your example so it includes the whole output that Angular produces: https://jsbin.com/rirogosiri/edit?html,css,output

The gold version is the "old" output that Angular 18 produces and that we rely on.

The aquamarine is what Angular 19 currently produces. And that one is not applying the color.

@GeorgySerga
Copy link
Contributor Author

GeorgySerga commented Nov 14, 2024

It does not, indeed, but it is correct. Both elements there have classes applied: .foo on one of them, .bar on the other. The selector says to not apply the styles to these elements :not(:host.foo, :host.bar).

EDIT: added a link to a bin with class applied if the host has a different class, .baz: https://jsbin.com/fucogaroxe/edit?html,css,output , but not to the other two instances, excluded by the selector.

@pkozlowski-opensource pkozlowski-opensource added the action: review The PR is still awaiting reviews from at least one requested reviewer label Nov 14, 2024
@pkozlowski-opensource
Copy link
Member

@GeorgySerga I've opened #58681 with your commits as we want to target the main branch

@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 Dec 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer area: compiler Issues related to `ngc`, Angular's template compiler target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants