Skip to content

Commit 66e940a

Browse files
puckowskidylhunn
authored andcommitted
feat(compiler): scope selectors in @starting-style (#53943)
make sure selectors inside @starting-style queries are correctly scoped PR Close #53943
1 parent 0accc64 commit 66e940a

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

packages/compiler/src/shadow_css.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const animationKeywords = new Set([
2626
'end', 'jump-both', 'jump-end', 'jump-none', 'jump-start', 'start'
2727
]);
2828

29+
/**
30+
* The following array contains all of the CSS at-rule identifiers which are scoped.
31+
*/
32+
const scopedAtRuleIdentifiers =
33+
['@media', '@supports', '@document', '@layer', '@container', '@scope', '@starting-style'];
34+
2935
/**
3036
* The following class has its origin from a port of shadowCSS from webcomponents.js to TypeScript.
3137
* It has since diverge in many ways to tailor Angular's needs.
@@ -557,10 +563,7 @@ export class ShadowCss {
557563
let content = rule.content;
558564
if (rule.selector[0] !== '@') {
559565
selector = this._scopeSelector(rule.selector, scopeSelector, hostSelector);
560-
} else if (
561-
rule.selector.startsWith('@media') || rule.selector.startsWith('@supports') ||
562-
rule.selector.startsWith('@document') || rule.selector.startsWith('@layer') ||
563-
rule.selector.startsWith('@container') || rule.selector.startsWith('@scope')) {
566+
} else if (scopedAtRuleIdentifiers.some(atRule => rule.selector.startsWith(atRule))) {
564567
content = this._scopeSelectors(rule.content, scopeSelector, hostSelector);
565568
} else if (rule.selector.startsWith('@font-face') || rule.selector.startsWith('@page')) {
566569
content = this._stripScopingSelectors(rule.content);

packages/compiler/test/shadow_css/at_rules_spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,20 @@ describe('ShadowCss, at-rules', () => {
216216
expect(shim(css, 'contenta')).toEqualCss(expected);
217217
});
218218
});
219+
220+
describe('@starting-style', () => {
221+
it('should scope normal selectors inside a starting-style rule', () => {
222+
const css = `
223+
@starting-style {
224+
img { border-radius: 50%; }
225+
.content { padding: 1em; }
226+
}`;
227+
const result = shim(css, 'host-a');
228+
expect(result).toEqualCss(`
229+
@starting-style {
230+
img[host-a] { border-radius: 50%; }
231+
.content[host-a] { padding: 1em; }
232+
}`);
233+
});
234+
});
219235
});

0 commit comments

Comments
 (0)