Skip to content

Commit bffc296

Browse files
authored
Update to core-js@3 (#6769)
* Update to core-js@3 * Remove references to @babel/polyfill
1 parent b29a163 commit bffc296

File tree

7 files changed

+71
-49
lines changed

7 files changed

+71
-49
lines changed

docusaurus/docs/supported-browsers-features.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_label: Supported Browsers and Features
66

77
## Supported Browsers
88

9-
By default, the generated project supports all modern browsers. Support for Internet Explorer 9, 10, and 11 requires polyfills. For a minimum set of polyfills to support older browsers, use [react-app-polyfill](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md). To polyfill other language features, see the [Adding Polyfills](#adding-polyfills) section below
9+
By default, the generated project supports all modern browsers. Support for Internet Explorer 9, 10, and 11 requires polyfills. For a set of polyfills to support older browsers, use [react-app-polyfill](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md).
1010

1111
## Supported Language Features
1212

@@ -27,10 +27,6 @@ Note that **this project includes no [polyfills](https://github.com/facebook/cre
2727

2828
If you use any other ES6+ features that need **runtime support** (such as `Array.from()` or `Symbol`), make sure you are [including the appropriate polyfills manually](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md), or that the browsers you are targeting already support them.
2929

30-
## Adding Polyfills
31-
32-
You can install [`@babel/polyfill`](https://babeljs.io/docs/en/babel-polyfill) as a dependency in your application, and import it at the very top of your app's entry point (`src/index.js` or `src/index.tsx`) to emulate a full ES2015+ environment. Your `browerslist` configuration will be used to only include the polyfills necessary by your target browsers.
33-
3430
## Configuring Supported Browsers
3531

3632
By default, the generated project includes a [`browerslist`](https://github.com/browserslist/browserslist) configuration in your `package.json` file to target a broad range of browsers based on global usage (`> 0.2%`) for production builds, and modern browsers for development. This gives a good development experience, especially when using language features such as async/await, but still provides high compatibility with many browsers in production.

packages/babel-preset-react-app/create.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ module.exports = function(api, opts, env) {
7979
// Latest stable ECMAScript features
8080
require('@babel/preset-env').default,
8181
{
82-
// Allow importing @babel/polyfill in entrypoint and use browserlist to select polyfills
82+
// Allow importing core-js in entrypoint and use browserlist to select polyfills
8383
useBuiltIns: 'entry',
8484
// Set the corejs version we are using to avoid warnings in console
8585
// This will need to change once we upgrade to corejs@3
86-
corejs: 2,
86+
corejs: 3,
8787
// Do not transform modules to CJS
8888
modules: false,
8989
// Exclude transforms that make all code slower

packages/react-app-polyfill/README.md

+46-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
This package includes polyfills for various browsers.
44
It includes minimum requirements and commonly used language features used by [Create React App](https://github.com/facebook/create-react-app) projects.
55

6-
### Features
7-
8-
Each polyfill ensures the following language features are present:
9-
10-
1. `Promise` (for `async` / `await` support)
11-
1. `window.fetch` (a Promise-based way to make web requests in the browser)
12-
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
13-
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
14-
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
15-
16-
_If you need more features, you must include them manually._
17-
186
### Usage
197

208
First, install the package using Yarn or npm:
@@ -29,7 +17,19 @@ or
2917
yarn add react-app-polyfill
3018
```
3119

32-
Now, 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.
20+
## Supporting Internet Explorer
21+
22+
You can import the entry point for the minimal version you intend to support to ensure that the minimum langauge features are present that are required to use Create React App. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.
23+
24+
These modules ensure the following language features are present:
25+
26+
1. `Promise` (for `async` / `await` support)
27+
1. `window.fetch` (a Promise-based way to make web requests in the browser)
28+
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
29+
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
30+
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
31+
32+
_If you need more features, see the [Polyfilling other language features](#polyfilling-other-language-features) section below._
3333

3434
#### Internet Explorer 9
3535

@@ -48,3 +48,36 @@ import 'react-app-polyfill/ie11';
4848

4949
// ...
5050
```
51+
52+
## Polyfilling other language features
53+
54+
You can also polyfill stable language features not available in your target browsers. If you're using this in Create React App, it will automatically use the `browserslist` you've defined to only include polyfills needed by your target browsers when importing the `stable` polyfill. **Make sure to follow the Internet Explorer steps above if you need to support Internet Explorer in your application**.
55+
56+
```js
57+
// This must be the first line in src/index.js
58+
import 'react-app-polyfill/stable';
59+
60+
// ...
61+
```
62+
63+
If you are supporting Internet Explorer 9 or Internet Explorer 11 you should include both the `ie9` or `ie11` and `stable` modules:
64+
65+
For IE9:
66+
67+
```js
68+
// These must be the first lines in src/index.js
69+
import 'react-app-polyfill/ie9';
70+
import 'react-app-polyfill/stable';
71+
72+
// ...
73+
```
74+
75+
For IE11:
76+
77+
```js
78+
// These must be the first lines in src/index.js
79+
import 'react-app-polyfill/ie11';
80+
import 'react-app-polyfill/stable';
81+
82+
// ...
83+
```

packages/react-app-polyfill/ie11.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ if (typeof window !== 'undefined') {
2626
Object.assign = require('object-assign');
2727

2828
// Support for...of (a commonly used syntax feature that requires Symbols)
29-
require('core-js/es6/symbol');
29+
require('core-js/features/symbol');
3030
// Support iterable spread (...Set, ...Map)
31-
require('core-js/fn/array/from');
31+
require('core-js/features/array/from');

packages/react-app-polyfill/ie9.js

+3-25
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,9 @@
66
*/
77
'use strict';
88

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-
// Make sure we're in a Browser-like environment before importing polyfills
18-
// This prevents `fetch()` from being imported in a Node test environment
19-
if (typeof window !== 'undefined') {
20-
// fetch() polyfill for making API calls.
21-
require('whatwg-fetch');
22-
}
23-
24-
// Object.assign() is commonly used with React.
25-
// It will use the native implementation if it's present and isn't buggy.
26-
Object.assign = require('object-assign');
27-
28-
// Support for...of (a commonly used syntax feature that requires Symbols)
29-
require('core-js/es6/symbol');
30-
// Support iterable spread (...Set, ...Map)
31-
require('core-js/fn/array/from');
9+
require('./ie11');
3210

3311
// React 16+ relies on Map, Set, and requestAnimationFrame
34-
require('core-js/es6/map');
35-
require('core-js/es6/set');
12+
require('core-js/features/map');
13+
require('core-js/features/set');
3614
require('raf').polyfill(window);

packages/react-app-polyfill/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
"files": [
1414
"ie9.js",
1515
"ie11.js",
16-
"jsdom.js"
16+
"jsdom.js",
17+
"stable.js"
1718
],
1819
"dependencies": {
19-
"core-js": "2.6.5",
20+
"core-js": "3.0.1",
2021
"object-assign": "4.1.1",
2122
"promise": "8.0.2",
2223
"raf": "3.4.1",
24+
"regenerator-runtime": "0.13.2",
2325
"whatwg-fetch": "3.0.0"
2426
}
2527
}

packages/react-app-polyfill/stable.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
// Polyfill stable language features.
10+
// It's recommended to use @babel/preset-env and browserslist
11+
// to only include the polyfills necessary for the target browsers.
12+
require('core-js/stable');
13+
require('regenerator-runtime/runtime');

0 commit comments

Comments
 (0)