Skip to content

Commit f63b99d

Browse files
Default sortShorthand to true (in extraction) to reduce configuration required. (#1740)
* Default `sortShorthand` to true to reduce configuration required. This matches the config we have internally at Atlassian and our recommended guidance and also matches the runtime sorting/bucketing (which has no configurable opt-out). * Fixup parcel snapshots (expected sorting changes
1 parent 18d2529 commit f63b99d

File tree

17 files changed

+114
-121
lines changed

17 files changed

+114
-121
lines changed

.changeset/plenty-feet-rest.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@compiled/babel-plugin-strip-runtime': minor
3+
'@compiled/parcel-optimizer': minor
4+
'@compiled/webpack-loader': minor
5+
'@compiled/css': minor
6+
---
7+
8+
Possibly BREAKING: Default `sortShorthand` to be enabled during stylesheet extraction to match the config we have internally at Atlassian and our recommendation.
9+
10+
You can opt-out from this change by setting `sortShorthand: false` in several places, refer to https://compiledcssinjs.com/docs/shorthand and package-specific documentation.
11+
12+
This is only a breaking change if you expect `margin:0` to override `margin-top:8px` for example, which in other CSS-in-JS libraries may actually work, but in Compiled it's not guaranteed to work, so we forcibly sort it to guarantee the order in which these styles are applied.

packages/babel-plugin-strip-runtime/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface PluginOptions {
3535
/**
3636
* Whether to sort shorthand and longhand properties,
3737
* eg. `margin` before `margin-top` for enforced determinism.
38-
* Defaults to `false`.
38+
* Defaults to `true`.
3939
*/
4040
sortShorthand?: boolean;
4141
}

packages/babel-plugin/src/css-map/__tests__/at-rules-and-selectors.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ describe('css map advanced functionality (at rules, selectors object)', () => {
239239
'._14jq32ev color{color:pink}',
240240
'._1wsc13q2 fontSize{background-color:blue}',
241241
'._1wyb12am{font-size:50px}',
242-
243-
'const styles={success:"_syazjafr _1wyb12am _14jq32ev _1wsc13q2"}',
242+
'const styles={success:"_syazjafr _1wyb12am _1wsc13q2 _14jq32ev"}',
244243
]);
245244
});
246245

packages/babel-plugin/src/keyframes/__tests__/behaviour.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Keyframes', () => {
2121
'._1wybgktf{font-size:20px}',
2222
'._2rko1l7b{border-radius:3px}',
2323
'._y44v1bcx{animation:kfwl3rt}',
24-
'{ax(["_1wybgktf _2rko1l7b _y44v1bcx", __cmplp.className])}',
24+
'{ax(["_2rko1l7b _y44v1bcx _1wybgktf", __cmplp.className])}',
2525
]);
2626
});
2727

@@ -45,7 +45,7 @@ describe('Keyframes', () => {
4545
'._y44v178k{animation:kvif0b9}',
4646
'._1wybgktf{font-size:20px}',
4747
'._2rko1l7b{border-radius:3px}',
48-
'{ax(["_y44v178k _1wybgktf _2rko1l7b", __cmplp.className])}',
48+
'{ax(["_y44v178k _2rko1l7b _1wybgktf", __cmplp.className])}',
4949
]);
5050
});
5151

@@ -69,7 +69,7 @@ describe('Keyframes', () => {
6969
expect(actual).toIncludeMultiple([
7070
'._syaz5scu{color:red}',
7171
'._y44v1bcx{animation:kfwl3rt}',
72-
'{ax(["_syaz5scu _y44v1bcx", __cmplp.className])}',
72+
'{ax(["_y44v1bcx _syaz5scu", __cmplp.className])}',
7373
]);
7474
});
7575

packages/babel-plugin/src/styled/__tests__/behaviour.test.ts

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ describe('styled component behaviour', () => {
122122
]);
123123
`);
124124

125-
expect(actual).toInclude('{font-size:12px}');
126-
expect(actual).toInclude('{color:blue}');
127-
expect(actual).toInclude('{font-weight:500}');
125+
expect(actual).toIncludeMultiple(['{font-size:12px}', '{color:blue}', '{font-weight:500}']);
128126
});
129127

130128
it('should not destructure valid html attributes from props', () => {
@@ -256,8 +254,10 @@ describe('styled component behaviour', () => {
256254
});
257255
`);
258256

259-
expect(actual).toInclude('{color:var(--_63bh2t)}');
260-
expect(actual).toInclude('"--_63bh2t":ix((()=>{return __cmplp.color;})())');
257+
expect(actual).toIncludeMultiple([
258+
'{color:var(--_63bh2t)}',
259+
'"--_63bh2t":ix((()=>{return __cmplp.color;})())',
260+
]);
261261
});
262262

263263
it('should transform an arrow function with a body into an IIFE by preventing passing down invalid html attributes to the node', () => {
@@ -269,9 +269,11 @@ describe('styled component behaviour', () => {
269269
});
270270
`);
271271

272-
expect(actual).toInclude('{font-size:var(--_1eiw442)}');
273-
expect(actual).toInclude('const{textSize,...__cmpldp}=__cmplp;');
274-
expect(actual).toInclude('"--_1eiw442":ix((()=>{return __cmplp.textSize;})())');
272+
expect(actual).toIncludeMultiple([
273+
'{font-size:var(--_1eiw442)}',
274+
'const{textSize,...__cmpldp}=__cmplp;',
275+
'"--_1eiw442":ix((()=>{return __cmplp.textSize;})())',
276+
]);
275277
});
276278

277279
it('should move suffix and prefix of a dynamic arrow function with a body into an IIFE', () => {
@@ -283,8 +285,10 @@ describe('styled component behaviour', () => {
283285
});
284286
`);
285287

286-
expect(actual).toInclude('{content:var(--_63bh2t)}');
287-
expect(actual).toInclude('"--_63bh2t":ix((()=>{return __cmplp.color;})(),"\\"","\\"")');
288+
expect(actual).toIncludeMultiple([
289+
'{content:var(--_63bh2t)}',
290+
'"--_63bh2t":ix((()=>{return __cmplp.color;})(),"\\"","\\"")',
291+
]);
288292
});
289293

290294
it('should collect args as styles', () => {
@@ -531,7 +535,7 @@ describe('styled component behaviour', () => {
531535
'._ca0qftgi{padding-top:8px}',
532536
'._19itlf8h{border:2px solid blue}',
533537
'._1wyb1ul9{font-size:30px}',
534-
'ax(["_1wyb1ul9 _19itlf8h _ca0qftgi _u5f3ftgi _n3tdftgi _19bvftgi",__cmplp.isPrimary?"_syaz13q2":"_syaz5scu",__cmplp.isDone?"_1hms1911":"_1hmsglyw",__cmplp.isClamped?"_1yyj11wp":"_1yyjkb7n",__cmplp.className])',
538+
'ax(["_19itlf8h _ca0qftgi _u5f3ftgi _n3tdftgi _19bvftgi _1wyb1ul9",__cmplp.isPrimary?"_syaz13q2":"_syaz5scu",__cmplp.isDone?"_1hms1911":"_1hmsglyw",__cmplp.isClamped?"_1yyj11wp":"_1yyjkb7n",__cmplp.className])',
535539
]);
536540
});
537541

@@ -624,11 +628,8 @@ describe('styled component behaviour', () => {
624628
'._syaz5scu{color:red}',
625629
'._syaz13q2{color:blue}',
626630
'._1wyb1ul9{font-size:30px}',
631+
`ax([\"_1wyb1ul9\",__cmplp.isPrimary?\"_syaz13q2\":\"_syaz5scu\",__cmplp.isPrimary?\"_19it1nsd\":\"_19it107e\",__cmplp.className]`,
627632
]);
628-
629-
expect(actual).toInclude(
630-
`ax([\"_1wyb1ul9\",__cmplp.isPrimary?\"_syaz13q2\":\"_syaz5scu\",__cmplp.isPrimary?\"_19it1nsd\":\"_19it107e\",__cmplp.className]`
631-
);
632633
});
633634

634635
it('should apply conditional CSS with nested ternary operators', () => {
@@ -653,7 +654,7 @@ describe('styled component behaviour', () => {
653654
'._syaz5scu{color:red}',
654655
'._syaz13q2{color:blue}',
655656
'._syaz11x8{color:black}',
656-
`ax([\"_1wyb1ul9 _19itlf8h _ca0qftgi _u5f3ftgi _n3tdftgi _19bvftgi\",__cmplp.isPrimary?__cmplp.isDisabled?\"_syaz11x8\":\"_syaz13q2\":\"_syaz5scu\",__cmplp.className])`,
657+
`ax([\"_19itlf8h _ca0qftgi _u5f3ftgi _n3tdftgi _19bvftgi _1wyb1ul9\",__cmplp.isPrimary?__cmplp.isDisabled?\"_syaz11x8\":\"_syaz13q2\":\"_syaz5scu\",__cmplp.className])`,
657658
]);
658659
});
659660

@@ -674,11 +675,8 @@ describe('styled component behaviour', () => {
674675
'._19it7fe6{border:3px solid yellow}',
675676
'._bfhk1x77{background-color:white}',
676677
'._syaz5scu{color:red}',
678+
'className={ax(["_bfhk1x77 _19it7fe6 _syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}',
677679
]);
678-
679-
expect(actual).toInclude(
680-
'className={ax(["_syaz5scu _bfhk1x77 _19it7fe6",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}'
681-
);
682680
});
683681

684682
it('should apply conditional CSS with template literal and nested ternary operators', () => {
@@ -733,11 +731,8 @@ describe('styled component behaviour', () => {
733731
'._k48p8n31{font-weight:bold}',
734732
'._syaz13q2{color:blue}',
735733
'._syaz5scu{color:red}',
734+
'className={ax(["_syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.isBolded&&"_k48p8n31",__cmplp.className])}',
736735
]);
737-
738-
expect(actual).toInclude(
739-
'className={ax(["_syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.isBolded&&"_k48p8n31",__cmplp.className])}'
740-
);
741736
});
742737

743738
it('should not allow a logical statement with a conditional right-hand side', () => {
@@ -838,11 +833,8 @@ describe('styled component behaviour', () => {
838833
'._19it7fe6{border:3px solid yellow}',
839834
'._bfhk1x77{background-color:white}',
840835
'._syaz5scu{color:red}',
836+
'{ax(["_bfhk1x77 _19it7fe6 _syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}',
841837
]);
842-
843-
expect(actual).toInclude(
844-
'{ax(["_syaz5scu _bfhk1x77 _19it7fe6",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}'
845-
);
846838
});
847839

848840
it('should apply unconditional after a conditional css rule with template literal', () => {
@@ -862,11 +854,8 @@ describe('styled component behaviour', () => {
862854
'._bfhk1x77{background-color:white}',
863855
'._syaz5scu{color:red}',
864856
'._19it7fe6{border:3px solid yellow}',
857+
'{ax(["_19it7fe6 _bfhk1x77 _syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}',
865858
]);
866-
867-
expect(actual).toInclude(
868-
'{ax(["_19it7fe6 _syaz5scu _bfhk1x77",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}'
869-
);
870859
});
871860

872861
it('should apply unconditional CSS with props', () => {
@@ -881,9 +870,8 @@ describe('styled component behaviour', () => {
881870
expect(actual).toIncludeMultiple([
882871
'const _="._syaz1q2z{color:var(--_1r7cl4y)}"',
883872
'"--_1r7cl4y":ix(__cmplp.primary)',
873+
'className={ax(["_syaz1q2z",__cmplp.className])}',
884874
]);
885-
886-
expect(actual).toInclude('className={ax(["_syaz1q2z",__cmplp.className])}');
887875
});
888876

889877
it('should apply unconditional CSS with and without props', () => {
@@ -900,9 +888,8 @@ describe('styled component behaviour', () => {
900888
'._syaz1q2z{color:var(--_1r7cl4y)}',
901889
'._bfhk5scu{background-color:red}',
902890
'--_1r7cl4y":ix(__cmplp.primary)}',
891+
'className={ax(["_bfhk5scu _syaz1q2z",__cmplp.className])}',
903892
]);
904-
905-
expect(actual).toInclude('className={ax(["_bfhk5scu _syaz1q2z",__cmplp.className])}');
906893
});
907894

908895
it('should apply conditional CSS with object styles', () => {
@@ -915,11 +902,11 @@ describe('styled component behaviour', () => {
915902
);
916903
`);
917904

918-
expect(actual).toIncludeMultiple(['._syaz13q2{color:blue}', '._syaz5scu{color:red}']);
919-
920-
expect(actual).toInclude(
921-
'className={ax(["_syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}'
922-
);
905+
expect(actual).toIncludeMultiple([
906+
'._syaz13q2{color:blue}',
907+
'._syaz5scu{color:red}',
908+
'className={ax(["_syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}',
909+
]);
923910
});
924911

925912
it('should apply conditional CSS with object styles and multiple props lines', () => {
@@ -937,11 +924,8 @@ describe('styled component behaviour', () => {
937924
'._k48p8n31{font-weight:bold}',
938925
'._syaz13q2{color:blue}',
939926
'._syaz5scu{color:red}',
927+
'className={ax(["_syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.isBolded&&"_k48p8n31",__cmplp.className])}',
940928
]);
941-
942-
expect(actual).toInclude(
943-
'className={ax(["_syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.isBolded&&"_k48p8n31",__cmplp.className])}'
944-
);
945929
});
946930

947931
it('should apply unconditional before and after a conditional css rule with object styles', () => {
@@ -955,15 +939,12 @@ describe('styled component behaviour', () => {
955939
);
956940
`);
957941

958-
expect.toIncludeMultiple([
942+
expect(actual).toIncludeMultiple([
959943
'._syaz13q2{color:blue}',
960944
'._19it97hw{border:1px solid black}',
961945
'._syaz5scu{color:red}',
946+
'{ax(["_19it97hw _syaz5scu",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}',
962947
]);
963-
964-
expect(actual).toInclude(
965-
'{ax(["_syaz5scu _19it97hw",__cmplp.isPrimary&&"_syaz13q2",__cmplp.className])}'
966-
);
967948
});
968949

969950
it('should apply conditional CSS with object styles regardless declaration order', () => {
@@ -976,11 +957,12 @@ describe('styled component behaviour', () => {
976957
);
977958
`);
978959

979-
expect(actual).toIncludeMultiple(['._syaz5scu{color:red}', '._syaz13q2{color:blue}']);
960+
expect(actual).toIncludeMultiple([
961+
'._syaz5scu{color:red}',
962+
'._syaz13q2{color:blue}',
980963

981-
expect(actual).toInclude(
982-
'className={ax(["_syaz13q2",__cmplp.isPrimary&&"_syaz5scu",__cmplp.className])}'
983-
);
964+
'className={ax(["_syaz13q2",__cmplp.isPrimary&&"_syaz5scu",__cmplp.className])}',
965+
]);
984966
});
985967

986968
it('should apply multi conditional logical expression', () => {
@@ -993,11 +975,11 @@ describe('styled component behaviour', () => {
993975
);
994976
`);
995977

996-
expect(actual).toIncludeMultiple(['._syaz13q2{color:blue}', '._syaz5scu{color:red}']);
997-
998-
expect(actual).toInclude(
999-
'{ax(["_syaz5scu",(__cmplp.isPrimary||__cmplp.isMaybe)&&"_syaz13q2",__cmplp.className])}'
1000-
);
978+
expect(actual).toIncludeMultiple([
979+
'._syaz13q2{color:blue}',
980+
'._syaz5scu{color:red}',
981+
'{ax(["_syaz5scu",(__cmplp.isPrimary||__cmplp.isMaybe)&&"_syaz13q2",__cmplp.className])}',
982+
]);
1001983
});
1002984

1003985
it('should apply multi conditional logical expression with different props lines and syntax styles', () => {
@@ -1030,11 +1012,11 @@ describe('styled component behaviour', () => {
10301012
);
10311013
`);
10321014

1033-
expect(actual).toIncludeMultiple(['._syaz13q2{color:blue}', '._syaz5scu{color:red}']);
1034-
1035-
expect(actual).toInclude(
1036-
'{ax(["_syaz5scu",__cmplp.isPrimary&&(__cmplp.isBolded||__cmplp.isFoo)&&"_syaz13q2",__cmplp.className])}'
1037-
);
1015+
expect(actual).toIncludeMultiple([
1016+
'._syaz13q2{color:blue}',
1017+
'._syaz5scu{color:red}',
1018+
'{ax(["_syaz5scu",__cmplp.isPrimary&&(__cmplp.isBolded||__cmplp.isFoo)&&"_syaz13q2",__cmplp.className])}',
1019+
]);
10381020
});
10391021

10401022
it('should apply conditional CSS with ternary and boolean in the same line', () => {
@@ -1070,9 +1052,8 @@ describe('styled component behaviour', () => {
10701052
expect(actual).toIncludeMultiple([
10711053
'._bfhk1x77{background-color:white}',
10721054
'._syazruxl{color:orange}',
1055+
'className={ax(["_bfhk1x77 _syazruxl",__cmplp.className])}',
10731056
]);
1074-
1075-
expect(actual).toInclude('className={ax(["_syazruxl _bfhk1x77",__cmplp.className])}');
10761057
});
10771058

10781059
it('should only add falsy condition when truthy condition has no value', () => {
@@ -1087,7 +1068,7 @@ describe('styled component behaviour', () => {
10871068
expect(actual).toIncludeMultiple([
10881069
'._syazbf54{color:green}',
10891070
'._bfhk11x8{background-color:black}',
1090-
'className={ax(["",!__cmplp.isPrimary&&"_syazbf54 _bfhk11x8",__cmplp.className])}',
1071+
'className={ax(["",!__cmplp.isPrimary&&"_bfhk11x8 _syazbf54",__cmplp.className])}',
10911072
]);
10921073
});
10931074

@@ -1103,7 +1084,7 @@ describe('styled component behaviour', () => {
11031084
expect(actual).toIncludeMultiple([
11041085
'._syazbf54{color:green}',
11051086
'._bfhk11x8{background-color:black}',
1106-
'className={ax(["",__cmplp.isPrimary&&"_syazbf54 _bfhk11x8",__cmplp.className])}',
1087+
'className={ax(["",__cmplp.isPrimary&&"_bfhk11x8 _syazbf54",__cmplp.className])}',
11071088
]);
11081089
});
11091090

packages/babel-plugin/src/styled/__tests__/tagged-template-expression.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ describe('styled tagged template expression', () => {
869869
870870
const color = 'red';
871871
const color2 = 'blue';
872-
872+
873873
const ListItem = styled.div\`
874874
background: linear-gradient(
875875
\${\`var(--my-variable, \${color})\`},
@@ -889,7 +889,7 @@ describe('styled tagged template expression', () => {
889889
890890
const color = 'red';
891891
const interpolation = \`1px solid \${\`var(--my-variable, \${color})\`}\`;
892-
892+
893893
const ListItem = styled.div\`
894894
border: \${interpolation};
895895
\`;
@@ -1062,7 +1062,7 @@ describe('styled tagged template expression', () => {
10621062
'._1wybgktf{font-size:20px}',
10631063
'._2rko1l7b{border-radius:3px}',
10641064
'._syaz1qjj{color:var(--_pvyxdf)}',
1065-
'{ax(["_1wybgktf _2rko1l7b _syaz1qjj", __cmplp.className])}',
1065+
'{ax(["_2rko1l7b _1wybgktf _syaz1qjj", __cmplp.className])}',
10661066
]);
10671067
});
10681068

@@ -1084,7 +1084,7 @@ describe('styled tagged template expression', () => {
10841084
'._syaz1qjj{color:var(--_pvyxdf)}',
10851085
'._1wybgktf{font-size:20px}',
10861086
'._2rko1l7b{border-radius:3px}',
1087-
'{ax(["_syaz1qjj _1wybgktf _2rko1l7b", __cmplp.className])}',
1087+
'{ax(["_2rko1l7b _syaz1qjj _1wybgktf", __cmplp.className])}',
10881088
]);
10891089
});
10901090
});

packages/css/src/__tests__/transform.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,10 @@ describe('#css-transform', () => {
409409
);
410410

411411
expect(actual.join('\n')).toMatchInlineSnapshot(`
412-
"._18u0idpf{margin-left:0}
412+
"._1h6d1r31{border-color:currentColor}
413+
._18u0idpf{margin-left:0}
413414
._1sb21e8g{content:"hello"}
414415
._syaz15td{color:#639}
415-
._1h6d1r31{border-color:currentColor}
416416
._bfhk1r31{background-color:currentColor}
417417
._5wra1r31{border-left-color:currentColor}"
418418
`);

0 commit comments

Comments
 (0)