Skip to content

Commit 9b9c818

Browse files
alan-agius4AndrewKushnir
authored andcommitted
perf(core): change RendererType2.styles to accept a only a flat array (#49072)
While unlikely, prior to this change it was possible to provide a nested array of styles to the render. This required the framework to handle this by doing a flatten operation. This change also renames the `flattenStyles` method as it no longer flattens the styles. BREAKING CHANGE: `RendererType2.styles` no longer accepts a nested arrays. Closes #48317 PR Close #49072
1 parent 2535883 commit 9b9c818

File tree

12 files changed

+31
-33
lines changed

12 files changed

+31
-33
lines changed

goldens/public-api/core/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ export interface RendererType2 {
12341234
};
12351235
encapsulation: ViewEncapsulation;
12361236
id: string;
1237-
styles: (string | any[])[];
1237+
styles: string[];
12381238
}
12391239

12401240
// @public

packages/core/src/render/api_flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface RendererType2 {
3434
/**
3535
* Defines CSS styles to be stored on a renderer instance.
3636
*/
37-
styles: (string|any[])[];
37+
styles: string[];
3838
/**
3939
* Defines arbitrary developer-defined data to be stored on a renderer instance.
4040
* This is useful for renderers that delegate to other renderers.

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,6 @@
869869
{
870870
"name": "findAttrIndexInNode"
871871
},
872-
{
873-
"name": "flattenStyles"
874-
},
875872
{
876873
"name": "flattenUnsubscriptionErrors"
877874
},
@@ -1406,6 +1403,9 @@
14061403
{
14071404
"name": "shareSubjectFactory"
14081405
},
1406+
{
1407+
"name": "shimStylesContent"
1408+
},
14091409
{
14101410
"name": "shouldSearchParent"
14111411
},

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,6 @@
632632
{
633633
"name": "findAttrIndexInNode"
634634
},
635-
{
636-
"name": "flattenStyles"
637-
},
638635
{
639636
"name": "flattenUnsubscriptionErrors"
640637
},
@@ -1073,6 +1070,9 @@
10731070
{
10741071
"name": "shareSubjectFactory"
10751072
},
1073+
{
1074+
"name": "shimStylesContent"
1075+
},
10761076
{
10771077
"name": "shouldSearchParent"
10781078
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,6 @@
884884
{
885885
"name": "findStylingValue"
886886
},
887-
{
888-
"name": "flattenStyles"
889-
},
890887
{
891888
"name": "flattenUnsubscriptionErrors"
892889
},
@@ -1559,6 +1556,9 @@
15591556
{
15601557
"name": "shareSubjectFactory"
15611558
},
1559+
{
1560+
"name": "shimStylesContent"
1561+
},
15621562
{
15631563
"name": "shouldSearchParent"
15641564
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,6 @@
854854
{
855855
"name": "findStylingValue"
856856
},
857-
{
858-
"name": "flattenStyles"
859-
},
860857
{
861858
"name": "flattenUnsubscriptionErrors"
862859
},
@@ -1535,6 +1532,9 @@
15351532
{
15361533
"name": "shareSubjectFactory"
15371534
},
1535+
{
1536+
"name": "shimStylesContent"
1537+
},
15381538
{
15391539
"name": "shouldSearchParent"
15401540
},

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,6 @@
11511151
{
11521152
"name": "flatten2"
11531153
},
1154-
{
1155-
"name": "flattenStyles"
1156-
},
11571154
{
11581155
"name": "flattenUnsubscriptionErrors"
11591156
},
@@ -1868,6 +1865,9 @@
18681865
{
18691866
"name": "shareSubjectFactory"
18701867
},
1868+
{
1869+
"name": "shimStylesContent"
1870+
},
18711871
{
18721872
"name": "shouldSearchParent"
18731873
},

packages/core/test/bundling/standalone_bootstrap/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,6 @@
560560
{
561561
"name": "extractDirectiveDef"
562562
},
563-
{
564-
"name": "flattenStyles"
565-
},
566563
{
567564
"name": "flattenUnsubscriptionErrors"
568565
},
@@ -929,6 +926,9 @@
929926
{
930927
"name": "shareSubjectFactory"
931928
},
929+
{
930+
"name": "shimStylesContent"
931+
},
932932
{
933933
"name": "shouldSearchParent"
934934
},

packages/core/test/bundling/todo/bundle.golden_symbols.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,6 @@
755755
{
756756
"name": "findStylingValue"
757757
},
758-
{
759-
"name": "flattenStyles"
760-
},
761758
{
762759
"name": "flattenUnsubscriptionErrors"
763760
},
@@ -1307,6 +1304,9 @@
13071304
{
13081305
"name": "shareSubjectFactory"
13091306
},
1307+
{
1308+
"name": "shimStylesContent"
1309+
},
13101310
{
13111311
"name": "shouldSearchParent"
13121312
},

packages/platform-browser/src/dom/dom_renderer.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ export function shimHostAttribute(componentShortId: string): string {
5353
return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
5454
}
5555

56-
export function flattenStyles(compId: string, styles: Array<string|string[]>): string[] {
57-
// Cannot use `Infinity` as depth as `infinity` is not a number literal in TypeScript.
58-
// See: https://github.com/microsoft/TypeScript/issues/32277
59-
return styles.flat(100).map(s => s.replace(COMPONENT_REGEX, compId));
56+
export function shimStylesContent(compId: string, styles: string[]): string[] {
57+
return styles.map(s => s.replace(COMPONENT_REGEX, compId));
6058
}
6159

6260
function decoratePreventDefault(eventHandler: Function): Function {
@@ -323,7 +321,7 @@ class ShadowDomRenderer extends DefaultDomRenderer2 {
323321
this.shadowRoot = (hostEl as any).attachShadow({mode: 'open'});
324322

325323
this.sharedStylesHost.addHost(this.shadowRoot);
326-
const styles = flattenStyles(component.id, component.styles);
324+
const styles = shimStylesContent(component.id, component.styles);
327325

328326
for (const style of styles) {
329327
const styleEl = document.createElement('style');
@@ -367,7 +365,7 @@ class NoneEncapsulationDomRenderer extends DefaultDomRenderer2 {
367365
compId = component.id,
368366
) {
369367
super(eventManager);
370-
this.styles = flattenStyles(compId, component.styles);
368+
this.styles = shimStylesContent(compId, component.styles);
371369
}
372370

373371
applyStyles(): void {

0 commit comments

Comments
 (0)