Skip to content

Commit 2a973d8

Browse files
authored
perf: drop IE11 support, reduce bundle by 4.3% (#5698)
* perf: drop IE11 support and reduce bundle size by 4.3% - Bump TS target from ES5 to ES2015, terser ecma to 2015 (eliminates __assign/__spreadArray polyfills, .concat() chains) - Compress domElements tag set (single-line array vs 155 individual strings) - Inline @emotion/unitless with IE-only entries removed (boxFlex, boxFlexGroup, boxOrdinalGroup, flexPositive, flexNegative, flexOrder, msGridRow, msGridRowSpan, msGridColumn, msGridColumnSpan) - Simplify DISABLE_SPEEDY env var detection (extract helper, dedupe guards) - Remove legacy React class statics from hoist (childContextTypes, contextTypes, mixins, getDefaultProps) - Remove hasSymbol guard (Symbol.for guaranteed in ES2015+) Bundle: 12.8kB → 12.25kB gzip (-550 bytes) * chore: update lockfile after removing @emotion/unitless * chore: add changeset for IE11 bundle savings * chore: remove domElements mention from changeset * fix: guard process.env.NODE_ENV fallback in DISABLE_SPEEDY * chore: revert prerelease version back to 6.3.12
1 parent 0507ace commit 2a973d8

9 files changed

Lines changed: 104 additions & 216 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"styled-components": minor
3+
---
4+
5+
Dropped IE11 support: ES2015 build target, inlined unitless CSS properties (removing @emotion/unitless dependency), removed legacy React class statics from hoist. Bundle reduced from 12.8kB to 12.25kB gzip (-4.3%).

‎packages/styled-components/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"homepage": "https://styled-components.com",
5858
"dependencies": {
5959
"@emotion/is-prop-valid": "1.4.0",
60-
"@emotion/unitless": "0.10.0",
6160
"@types/stylis": "4.2.7",
6261
"css-to-react-native": "3.2.0",
6362
"csstype": "3.2.3",
@@ -136,7 +135,7 @@
136135
"files": [
137136
{
138137
"path": "./dist/styled-components.min.js",
139-
"maxSize": "12.8kB"
138+
"maxSize": "12.3kB"
140139
}
141140
]
142141
},

‎packages/styled-components/rollup.config.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const minifierPlugin = terser({
104104
keep_infinity: true,
105105
pure_getters: true,
106106
},
107-
ecma: 5,
107+
ecma: 2015,
108108
format: {
109109
wrap_func_args: false,
110110
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/,

‎packages/styled-components/src/constants.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== '
2525
*/
2626
export const IS_RSC: boolean = typeof React.createContext === 'undefined';
2727

28+
function readSpeedyFlag(name: string): boolean | undefined {
29+
if (typeof process !== 'undefined' && typeof process.env !== 'undefined') {
30+
const val = process.env[name];
31+
if (val !== undefined && val !== '') {
32+
return val !== 'false';
33+
}
34+
}
35+
return undefined;
36+
}
37+
2838
export const DISABLE_SPEEDY = Boolean(
2939
typeof SC_DISABLE_SPEEDY === 'boolean'
3040
? SC_DISABLE_SPEEDY
31-
: typeof process !== 'undefined' &&
32-
typeof process.env !== 'undefined' &&
33-
typeof process.env.REACT_APP_SC_DISABLE_SPEEDY !== 'undefined' &&
34-
process.env.REACT_APP_SC_DISABLE_SPEEDY !== ''
35-
? process.env.REACT_APP_SC_DISABLE_SPEEDY === 'false'
36-
? false
37-
: process.env.REACT_APP_SC_DISABLE_SPEEDY
38-
: typeof process !== 'undefined' &&
39-
typeof process.env !== 'undefined' &&
40-
typeof process.env.SC_DISABLE_SPEEDY !== 'undefined' &&
41-
process.env.SC_DISABLE_SPEEDY !== ''
42-
? process.env.SC_DISABLE_SPEEDY === 'false'
43-
? false
44-
: process.env.SC_DISABLE_SPEEDY
45-
: process.env.NODE_ENV !== 'production'
41+
: (readSpeedyFlag('REACT_APP_SC_DISABLE_SPEEDY') ??
42+
readSpeedyFlag('SC_DISABLE_SPEEDY') ??
43+
(typeof process !== 'undefined' && typeof process.env !== 'undefined'
44+
? process.env.NODE_ENV !== 'production'
45+
: true))
4646
);
4747

4848
export const KEYFRAMES_ID_PREFIX = 'sc-keyframes-';

‎packages/styled-components/src/utils/addUnitIfNeeded.ts‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
1-
import unitless from '@emotion/unitless';
1+
/**
2+
* CSS properties that accept unitless numeric values.
3+
* Inlined from @emotion/unitless with IE-only entries removed
4+
* (boxFlex, boxFlexGroup, boxOrdinalGroup, flexPositive, flexNegative,
5+
* flexOrder, msGridRow, msGridRowSpan, msGridColumn, msGridColumnSpan).
6+
*/
7+
const unitless: Record<string, 1> = {
8+
animationIterationCount: 1,
9+
aspectRatio: 1,
10+
borderImageOutset: 1,
11+
borderImageSlice: 1,
12+
borderImageWidth: 1,
13+
columnCount: 1,
14+
columns: 1,
15+
flex: 1,
16+
flexGrow: 1,
17+
flexShrink: 1,
18+
gridRow: 1,
19+
gridRowEnd: 1,
20+
gridRowSpan: 1,
21+
gridRowStart: 1,
22+
gridColumn: 1,
23+
gridColumnEnd: 1,
24+
gridColumnSpan: 1,
25+
gridColumnStart: 1,
26+
fontWeight: 1,
27+
lineHeight: 1,
28+
opacity: 1,
29+
order: 1,
30+
orphans: 1,
31+
scale: 1,
32+
tabSize: 1,
33+
widows: 1,
34+
zIndex: 1,
35+
zoom: 1,
36+
WebkitLineClamp: 1,
37+
fillOpacity: 1,
38+
floodOpacity: 1,
39+
stopOpacity: 1,
40+
strokeDasharray: 1,
41+
strokeDashoffset: 1,
42+
strokeMiterlimit: 1,
43+
strokeOpacity: 1,
44+
strokeWidth: 1,
45+
};
246

347
// Taken from https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/shared/dangerousStyleValue.js
448
export default function addUnitIfNeeded(name: string, value: any) {

‎packages/styled-components/src/utils/domElements.ts‎

Lines changed: 2 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,6 @@
1+
// prettier-ignore
12
const elements = [
2-
'a',
3-
'abbr',
4-
'address',
5-
'area',
6-
'article',
7-
'aside',
8-
'audio',
9-
'b',
10-
'bdi',
11-
'bdo',
12-
'blockquote',
13-
'body',
14-
'button',
15-
'br',
16-
'canvas',
17-
'caption',
18-
'cite',
19-
'code',
20-
'col',
21-
'colgroup',
22-
'data',
23-
'datalist',
24-
'dd',
25-
'del',
26-
'details',
27-
'dfn',
28-
'dialog',
29-
'div',
30-
'dl',
31-
'dt',
32-
'em',
33-
'embed',
34-
'fieldset',
35-
'figcaption',
36-
'figure',
37-
'footer',
38-
'form',
39-
'h1',
40-
'h2',
41-
'h3',
42-
'h4',
43-
'h5',
44-
'h6',
45-
'header',
46-
'hgroup',
47-
'hr',
48-
'html',
49-
'i',
50-
'iframe',
51-
'img',
52-
'input',
53-
'ins',
54-
'kbd',
55-
'label',
56-
'legend',
57-
'li',
58-
'main',
59-
'map',
60-
'mark',
61-
'menu',
62-
'meter',
63-
'nav',
64-
'object',
65-
'ol',
66-
'optgroup',
67-
'option',
68-
'output',
69-
'p',
70-
'picture',
71-
'pre',
72-
'progress',
73-
'q',
74-
'rp',
75-
'rt',
76-
'ruby',
77-
's',
78-
'samp',
79-
'search',
80-
'section',
81-
'select',
82-
'slot',
83-
'small',
84-
'span',
85-
'strong',
86-
'sub',
87-
'summary',
88-
'sup',
89-
'table',
90-
'tbody',
91-
'td',
92-
'template',
93-
'textarea',
94-
'tfoot',
95-
'th',
96-
'thead',
97-
'time',
98-
'tr',
99-
'u',
100-
'ul',
101-
'var',
102-
'video',
103-
'wbr',
104-
'circle',
105-
'clipPath',
106-
'defs',
107-
'ellipse',
108-
'feBlend',
109-
'feColorMatrix',
110-
'feComponentTransfer',
111-
'feComposite',
112-
'feConvolveMatrix',
113-
'feDiffuseLighting',
114-
'feDisplacementMap',
115-
'feDistantLight',
116-
'feDropShadow',
117-
'feFlood',
118-
'feFuncA',
119-
'feFuncB',
120-
'feFuncG',
121-
'feFuncR',
122-
'feGaussianBlur',
123-
'feImage',
124-
'feMerge',
125-
'feMergeNode',
126-
'feMorphology',
127-
'feOffset',
128-
'fePointLight',
129-
'feSpecularLighting',
130-
'feSpotLight',
131-
'feTile',
132-
'feTurbulence',
133-
'filter',
134-
'foreignObject',
135-
'g',
136-
'image',
137-
'line',
138-
'linearGradient',
139-
'marker',
140-
'mask',
141-
'path',
142-
'pattern',
143-
'polygon',
144-
'polyline',
145-
'radialGradient',
146-
'rect',
147-
'stop',
148-
'svg',
149-
'switch',
150-
'symbol',
151-
'text',
152-
'textPath',
153-
'tspan',
154-
'use',
3+
'a','abbr','address','area','article','aside','audio','b','bdi','bdo','blockquote','body','button','br','canvas','caption','cite','code','col','colgroup','data','datalist','dd','del','details','dfn','dialog','div','dl','dt','em','embed','fieldset','figcaption','figure','footer','form','h1','h2','h3','h4','h5','h6','header','hgroup','hr','html','i','iframe','img','input','ins','kbd','label','legend','li','main','map','mark','menu','meter','nav','object','ol','optgroup','option','output','p','picture','pre','progress','q','rp','rt','ruby','s','samp','search','section','select','slot','small','span','strong','sub','summary','sup','table','tbody','td','template','textarea','tfoot','th','thead','time','tr','u','ul','var','video','wbr','circle','clipPath','defs','ellipse','feBlend','feColorMatrix','feComponentTransfer','feComposite','feConvolveMatrix','feDiffuseLighting','feDisplacementMap','feDistantLight','feDropShadow','feFlood','feFuncA','feFuncB','feFuncG','feFuncR','feGaussianBlur','feImage','feMerge','feMergeNode','feMorphology','feOffset','fePointLight','feSpecularLighting','feSpotLight','feTile','feTurbulence','filter','foreignObject','g','image','line','linearGradient','marker','mask','path','pattern','polygon','polyline','radialGradient','rect','stop','svg','switch','symbol','text','textPath','tspan','use',
1554
] as const;
1565

1576
export default new Set(elements);

‎packages/styled-components/src/utils/hoist.ts‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import React from 'react';
22
import { AnyComponent } from '../types';
33

4-
const hasSymbol = typeof Symbol === 'function' && Symbol.for;
5-
64
// copied from react-is
7-
const REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
8-
const REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
5+
const REACT_MEMO_TYPE = Symbol.for('react.memo');
6+
const REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
97

108
/**
119
* Adapted from hoist-non-react-statics to avoid the react-is dependency.
1210
*/
1311
const REACT_STATICS = {
14-
childContextTypes: true,
1512
contextType: true,
16-
contextTypes: true,
1713
defaultProps: true,
1814
displayName: true,
19-
getDefaultProps: true,
2015
getDerivedStateFromError: true,
2116
getDerivedStateFromProps: true,
22-
mixins: true,
2317
propTypes: true,
2418
type: true,
2519
};
@@ -51,7 +45,7 @@ const MEMO_STATICS = {
5145
type: true,
5246
};
5347

54-
const TYPE_STATICS = {
48+
const TYPE_STATICS: Record<symbol, Record<string, boolean>> = {
5549
[REACT_FORWARD_REF_TYPE]: FORWARD_REF_STATICS,
5650
[REACT_MEMO_TYPE]: MEMO_STATICS,
5751
};
@@ -75,7 +69,7 @@ function getStatics(component: OmniComponent) {
7569

7670
// React v16.12 and above
7771
return '$$typeof' in component
78-
? TYPE_STATICS[component['$$typeof'] as unknown as string]
72+
? TYPE_STATICS[component['$$typeof'] as unknown as symbol]
7973
: REACT_STATICS;
8074
}
8175

@@ -109,24 +103,20 @@ export default function hoistNonReactStatics<
109103
if (typeof sourceComponent !== 'string') {
110104
// don't hoist over string (html) components
111105

112-
if (objectPrototype) {
113-
const inheritedComponent = getPrototypeOf(sourceComponent);
114-
if (inheritedComponent && inheritedComponent !== objectPrototype) {
115-
hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);
116-
}
106+
const inheritedComponent = getPrototypeOf(sourceComponent);
107+
if (inheritedComponent && inheritedComponent !== objectPrototype) {
108+
hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);
117109
}
118110

119-
let keys: (String | Symbol)[] = getOwnPropertyNames(sourceComponent);
120-
121-
if (getOwnPropertySymbols) {
122-
keys = keys.concat(getOwnPropertySymbols(sourceComponent));
123-
}
111+
const keys: (string | symbol)[] = (
112+
getOwnPropertyNames(sourceComponent) as (string | symbol)[]
113+
).concat(getOwnPropertySymbols(sourceComponent));
124114

125115
const targetStatics = getStatics(targetComponent);
126116
const sourceStatics = getStatics(sourceComponent);
127117

128118
for (let i = 0; i < keys.length; ++i) {
129-
const key = keys[i] as unknown as string;
119+
const key = keys[i] as string;
130120
if (
131121
!(key in KNOWN_STATICS) &&
132122
!(excludelist && excludelist[key]) &&

‎packages/styled-components/tsconfig.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Basic Options */
1010
"incremental": true /* Enable incremental compilation */,
11-
"target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
11+
"target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
1212
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
1313
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
1414
// "allowJs": true, /* Allow javascript files to be compiled. */
@@ -26,7 +26,7 @@
2626
// "removeComments": true, /* Do not emit comments to output. */
2727
"noEmit": true /* Do not emit outputs. */,
2828
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
29-
"downlevelIteration": false /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
29+
// downlevelIteration not needed with ES2015+ target
3030
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
3131

3232
/* Strict Type-Checking Options */

0 commit comments

Comments
 (0)