From 6d7741e897e61fc71ee67df948de03efbc62f225 Mon Sep 17 00:00:00 2001
From: Dan Abramov <dan.abramov@gmail.com>
Date: Wed, 27 Jul 2016 13:04:13 +0100
Subject: [PATCH] Add Promise and fetch polyfills (#235)

---
 config/polyfills.js           | 9 +++++++++
 config/webpack.config.dev.js  | 1 +
 config/webpack.config.prod.js | 5 ++++-
 package.json                  | 4 +++-
 scripts/eject.js              | 1 +
 5 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 config/polyfills.js

diff --git a/config/polyfills.js b/config/polyfills.js
new file mode 100644
index 000000000..0a0bd9504
--- /dev/null
+++ b/config/polyfills.js
@@ -0,0 +1,9 @@
+if (typeof Promise === 'undefined') {
+  // Rejection tracking prevents a common issue where React gets into an
+  // inconsistent state due to an error, but it gets swallowed by a Promise,
+  // and the user has no idea what causes React's erratic future behavior.
+  require('promise/lib/rejection-tracking').enable();
+  window.Promise = require('promise/lib/es6-extensions.js');
+}
+
+require('whatwg-fetch');
diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js
index db68112c4..3c5c7a5b5 100644
--- a/config/webpack.config.dev.js
+++ b/config/webpack.config.dev.js
@@ -18,6 +18,7 @@ module.exports = {
   entry: [
     require.resolve('webpack-dev-server/client') + '?http://localhost:3000',
     require.resolve('webpack/hot/dev-server'),
+    require.resolve('./polyfills'),
     path.join(paths.appSrc, 'index')
   ],
   output: {
diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js
index 923554b6a..a5a848f23 100644
--- a/config/webpack.config.prod.js
+++ b/config/webpack.config.prod.js
@@ -25,7 +25,10 @@ if (!publicPath.endsWith('/')) {
 module.exports = {
   bail: true,
   devtool: 'source-map',
-  entry: path.join(paths.appSrc, 'index'),
+  entry: [
+    require.resolve('./polyfills'),
+    path.join(paths.appSrc, 'index')
+  ],
   output: {
     path: paths.appBuild,
     filename: '[name].[chunkhash:8].js',
diff --git a/package.json b/package.json
index f0f2c29f6..85e93dc84 100644
--- a/package.json
+++ b/package.json
@@ -53,11 +53,13 @@
     "json-loader": "0.5.4",
     "opn": "4.0.2",
     "postcss-loader": "0.9.1",
+    "promise": "7.1.1",
     "rimraf": "2.5.3",
     "style-loader": "0.13.1",
     "url-loader": "0.5.7",
     "webpack": "1.13.1",
-    "webpack-dev-server": "1.14.1"
+    "webpack-dev-server": "1.14.1",
+    "whatwg-fetch": "1.0.0"
   },
   "devDependencies": {
     "bundle-deps": "1.0.0",
diff --git a/scripts/eject.js b/scripts/eject.js
index b3d7b4ae6..60ec9b9a5 100644
--- a/scripts/eject.js
+++ b/scripts/eject.js
@@ -47,6 +47,7 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
     path.join('config', 'flow', 'file.js.flow'),
     path.join('config', 'eslint.js'),
     path.join('config', 'paths.js'),
+    path.join('config', 'polyfills.js'),
     path.join('config', 'webpack.config.dev.js'),
     path.join('config', 'webpack.config.prod.js'),
     path.join('scripts', 'build.js'),
-- 
GitLab