fix(compiler): handle :host-context with comma-separated child selector#59276
Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
Closed
fix(compiler): handle :host-context with comma-separated child selector#59276crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto wants to merge 1 commit intoangular:mainfrom
Conversation
Both `:host` and `:host-context` work by looking for a specific character sequence that is terminated by `,` or `{` and replacing selectors inside of it with scoped versions. This is implemented as a regex which isn't aware of things like nested selectors. Normally this is fine for `:host`, because each `:host` produces one scoped selector which doesn't affect any child selectors, however it breaks down with `:host-context` which replaces each instance with two selectors. For example, if we have a selector in the form of `:host-context(.foo) a:not(.a, .b)`, the compiler ends up determining that `.a,` is the end selector and produces `.foo[a-host] a[contenta]:not(.a, .foo [a-host] a[contenta]:not(.a, .b) {}`.
These changes resolve the issue by splitting the CSS alogn top-level commas, processing the `:host-context` in them individually, and stiching the CSS back together.
Member
Author
|
Passing TGP, aside from some unrelated broken targets. |
Contributor
|
// cc @mattrberry |
Member
|
This makes me want to remove support for |
devversion
approved these changes
Jan 21, 2025
| const _parenSuffix = '(?:\\((' + '(?:\\([^)(]*\\)|[^)(]*)+?' + ')\\))'; | ||
| const _cssColonHostRe = new RegExp(_polyfillHost + _parenSuffix + '?([^,{]*)', 'gim'); | ||
| // note: :host-context patterns are terminated with `{`, as opposed to :host which | ||
| // is both `{` and `,` because :host-context handles top-level commas differently. |
Member
There was a problem hiding this comment.
OOC: do you have any information on this?
Contributor
|
This PR was merged into the repository by commit 98f8207. The changes were merged into the following branches: main, 19.1.x |
AndrewKushnir
pushed a commit
that referenced
this pull request
Jan 21, 2025
…or (#59276) Both `:host` and `:host-context` work by looking for a specific character sequence that is terminated by `,` or `{` and replacing selectors inside of it with scoped versions. This is implemented as a regex which isn't aware of things like nested selectors. Normally this is fine for `:host`, because each `:host` produces one scoped selector which doesn't affect any child selectors, however it breaks down with `:host-context` which replaces each instance with two selectors. For example, if we have a selector in the form of `:host-context(.foo) a:not(.a, .b)`, the compiler ends up determining that `.a,` is the end selector and produces `.foo[a-host] a[contenta]:not(.a, .foo [a-host] a[contenta]:not(.a, .b) {}`. These changes resolve the issue by splitting the CSS alogn top-level commas, processing the `:host-context` in them individually, and stiching the CSS back together. PR Close #59276
PrajaktaB27
pushed a commit
to PrajaktaB27/angular
that referenced
this pull request
Feb 7, 2025
…or (angular#59276) Both `:host` and `:host-context` work by looking for a specific character sequence that is terminated by `,` or `{` and replacing selectors inside of it with scoped versions. This is implemented as a regex which isn't aware of things like nested selectors. Normally this is fine for `:host`, because each `:host` produces one scoped selector which doesn't affect any child selectors, however it breaks down with `:host-context` which replaces each instance with two selectors. For example, if we have a selector in the form of `:host-context(.foo) a:not(.a, .b)`, the compiler ends up determining that `.a,` is the end selector and produces `.foo[a-host] a[contenta]:not(.a, .foo [a-host] a[contenta]:not(.a, .b) {}`. These changes resolve the issue by splitting the CSS alogn top-level commas, processing the `:host-context` in them individually, and stiching the CSS back together. PR Close angular#59276
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
:hostand:host-contextwork by looking for a specific character sequence that is terminated by,or{and replacing selectors inside of it with scoped versions. This is implemented as a regex which isn't aware of things like nested selectors. Normally this is fine for:host, because each:hostproduces one scoped selector which doesn't affect any child selectors, however it breaks down with:host-contextwhich replaces each instance with two selectors. For example, if we have a selector in the form of:host-context(.foo) a:not(.a, .b), the compiler ends up determining that.a,is the end selector and produces.foo[a-host] a[contenta]:not(.a, .foo [a-host] a[contenta]:not(.a, .b) {}.These changes resolve the issue by splitting the CSS alogn top-level commas, processing the
:host-contextin them individually, and stiching the CSS back together.