Skip to content

Commit 5599eff

Browse files
authored
Drop IE 11 support by default (#5090)
* Drop ie 11 support and move polyfills to a new package * More useful directions for what entry point to use #5090 (comment) * Clear up what file this polyfill goes in #5090 (comment) * Polyfill `window`, not `global` * Remove proxy polyfill file
1 parent 5f381e7 commit 5599eff

File tree

9 files changed

+116
-18
lines changed

9 files changed

+116
-18
lines changed

Diff for: packages/react-app-polyfill/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# react-app-polyfill
2+
3+
This package includes polyfills for various browsers.
4+
It includes minimum requirements and commonly used language features used by [Create React App](https://github.com/facebook/create-react-app) projects.<br>
5+
Please refer to its documentation:
6+
7+
- [Getting Started](https://github.com/facebook/create-react-app/blob/master/README.md#getting-started) – How to create a new app.
8+
- [User Guide](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App.
9+
10+
### Features
11+
12+
Each polyfill ensures the following language features are present:
13+
14+
1. `Promise` (for `async` / `await` support)
15+
1. `window.fetch` (a Promise-based way to make web requests in the browser)
16+
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
17+
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
18+
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
19+
20+
### Entry Points
21+
22+
You can import the entry point for the minimal version you intend to support. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.
23+
24+
#### Internet Explorer 9
25+
26+
```js
27+
// This must be the first line in src/index.js
28+
import 'react-app-polyfill/ie9';
29+
30+
// ...
31+
```
32+
33+
#### Internet Explorer 11
34+
35+
```js
36+
// This must be the first line in src/index.js
37+
import 'react-app-polyfill/ie11';
38+
39+
// ...
40+
```

Diff for: packages/react-scripts/config/polyfills.js renamed to packages/react-app-polyfill/ie11.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// @remove-on-eject-begin
21
/**
32
* Copyright (c) 2015-present, Facebook, Inc.
43
*
54
* This source code is licensed under the MIT license found in the
65
* LICENSE file in the root directory of this source tree.
76
*/
8-
// @remove-on-eject-end
97
'use strict';
108

119
if (typeof Promise === 'undefined') {
@@ -23,8 +21,7 @@ require('whatwg-fetch');
2321
// It will use the native implementation if it's present and isn't buggy.
2422
Object.assign = require('object-assign');
2523

26-
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
27-
// We don't polyfill it in the browser--this is user's responsibility.
28-
if (process.env.NODE_ENV === 'test') {
29-
require('raf').polyfill(global);
30-
}
24+
// Support for...of (a commonly used syntax feature that requires Symbols)
25+
require('core-js/es6/symbol');
26+
// Support iterable spread (...Set, ...Map)
27+
require('core-js/fn/array/from');

Diff for: packages/react-app-polyfill/ie9.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
if (typeof Promise === 'undefined') {
10+
// Rejection tracking prevents a common issue where React gets into an
11+
// inconsistent state due to an error, but it gets swallowed by a Promise,
12+
// and the user has no idea what causes React's erratic future behavior.
13+
require('promise/lib/rejection-tracking').enable();
14+
window.Promise = require('promise/lib/es6-extensions.js');
15+
}
16+
17+
// fetch() polyfill for making API calls.
18+
require('whatwg-fetch');
19+
20+
// Object.assign() is commonly used with React.
21+
// It will use the native implementation if it's present and isn't buggy.
22+
Object.assign = require('object-assign');
23+
24+
// Support for...of (a commonly used syntax feature that requires Symbols)
25+
require('core-js/es6/symbol');
26+
// Support iterable spread (...Set, ...Map)
27+
require('core-js/fn/array/from');
28+
29+
// React 16+ relies on Map, Set, and requestAnimationFrame
30+
require('core-js/es6/map');
31+
require('core-js/es6/set');
32+
require('raf').polyfill(window);

Diff for: packages/react-app-polyfill/jsdom.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
'use strict';
8+
9+
// fetch() polyfill for making API calls.
10+
require('whatwg-fetch');

Diff for: packages/react-app-polyfill/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "react-app-polyfill",
3+
"version": "0.0.0",
4+
"description": "Polyfills for various browsers including commonly used language features",
5+
"repository": "facebook/create-react-app",
6+
"license": "MIT",
7+
"bugs": {
8+
"url": "https://github.com/facebook/create-react-app/issues"
9+
},
10+
"engines": {
11+
"node": ">=6"
12+
},
13+
"files": [
14+
"ie9.js",
15+
"ie11.js",
16+
"jsdom.js"
17+
],
18+
"dependencies": {
19+
"core-js": "2.5.7",
20+
"object-assign": "4.1.1",
21+
"promise": "8.0.2",
22+
"raf": "3.4.0",
23+
"whatwg-fetch": "3.0.0"
24+
}
25+
}

Diff for: packages/react-scripts/config/webpack.config.dev.js

-3
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ module.exports = {
8282
devtool: 'cheap-module-source-map',
8383
// These are the "entry points" to our application.
8484
// This means they will be the "root" imports that are included in JS bundle.
85-
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
8685
entry: [
87-
// We ship a few polyfills by default:
88-
require.resolve('./polyfills'),
8986
// Include an alternative client for WebpackDevServer. A client's job is to
9087
// connect to WebpackDevServer by a socket and get notified about changes.
9188
// When you save a file, the client will either apply hot updates (in case

Diff for: packages/react-scripts/config/webpack.config.prod.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ module.exports = {
100100
// We generate sourcemaps in production. This is slow but gives good results.
101101
// You can exclude the *.map files from the build during deployment.
102102
devtool: shouldUseSourceMap ? 'source-map' : false,
103-
// In production, we only want to load the polyfills and the app code.
104-
entry: [require.resolve('./polyfills'), paths.appIndexJs],
103+
// In production, we only want to load the app code.
104+
entry: [paths.appIndexJs],
105105
output: {
106106
// The build folder.
107107
path: paths.appBuild,

Diff for: packages/react-scripts/package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@
5050
"jest": "23.6.0",
5151
"loader-utils": "1.1.0",
5252
"mini-css-extract-plugin": "0.4.3",
53-
"object-assign": "4.1.1",
5453
"optimize-css-assets-webpack-plugin": "5.0.1",
5554
"postcss-flexbugs-fixes": "4.1.0",
5655
"postcss-loader": "3.0.0",
5756
"postcss-preset-env": "6.0.6",
5857
"postcss-safe-parser": "4.0.1",
59-
"promise": "8.0.2",
60-
"raf": "3.4.0",
58+
"react-app-polyfill": "^0.0.0",
6159
"react-dev-utils": "^5.0.0",
6260
"resolve": "1.8.1",
6361
"sass-loader": "7.1.0",
@@ -68,8 +66,7 @@
6866
"url-loader": "1.1.1",
6967
"webpack": "4.19.1",
7068
"webpack-dev-server": "3.1.9",
71-
"webpack-manifest-plugin": "2.0.4",
72-
"whatwg-fetch": "3.0.0"
69+
"webpack-manifest-plugin": "2.0.4"
7370
},
7471
"devDependencies": {
7572
"react": "^16.3.2",

Diff for: packages/react-scripts/scripts/utils/createJestConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
2222
// in Jest configs. We need help from somebody with Windows to determine this.
2323
const config = {
2424
collectCoverageFrom: ['src/**/*.{js,jsx}'],
25-
setupFiles: [resolve('config/polyfills.js')],
25+
setupFiles: ['react-app-polyfill/jsdom'],
2626
setupTestFrameworkScriptFile: setupTestsFile,
2727
testMatch: [
2828
'<rootDir>/src/**/__tests__/**/*.{js,jsx}',

0 commit comments

Comments
 (0)