Skip to content

Commit

Permalink
Remove old IE polyfill code (#10238)
Browse files Browse the repository at this point in the history
* Upgrade DOM Fixtures

Upgrade to react-scripts v1 and include required polyfills for older
browsers

* Remove ChangeEvent polyfills for unsupported browsers
  • Loading branch information
jquense authored and gaearon committed Aug 3, 2017
1 parent c1833b4 commit 0b220d0
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 253 deletions.
5 changes: 3 additions & 2 deletions fixtures/dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.9.5"
"react-scripts": "1.0.0"
},
"dependencies": {
"classnames": "^2.2.5",
"query-string": "^4.2.3",
"core-js": "^2.4.1",
"prop-types": "^15.5.6",
"query-string": "^4.2.3",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"semver": "^5.3.0"
Expand Down
1 change: 0 additions & 1 deletion fixtures/dom/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
-->
<title>React App</title>
<script src="https://unpkg.com/prop-types@15.5.6/prop-types.js"></script>
<script src="react-loader.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
43 changes: 0 additions & 43 deletions fixtures/dom/public/react-loader.js

This file was deleted.

4 changes: 2 additions & 2 deletions fixtures/dom/src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const React = window.React;
import Header from './Header';
import Fixtures from './fixtures';

import '../style.css';

const React = window.React;

function App() {
return (
<div>
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/components/fixtures/buttons/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const React = window.React;

import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';

const React = window.React;

function onButtonClick() {
window.alert(`This shouldn't have happened!`);
}
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/components/fixtures/error-handling/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const React = window.React;

import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';

const React = window.React;

function BadRender(props) {
throw props.error;
}
Expand Down
5 changes: 3 additions & 2 deletions fixtures/dom/src/components/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const React = window.React;
import RangeInputFixtures from './range-inputs';
import TextInputFixtures from './text-inputs';
import SelectFixtures from './selects';
Expand All @@ -10,6 +9,8 @@ import ButtonFixtures from './buttons';
import DateInputFixtures from './date-inputs';
import ErrorHandling from './error-handling';

const React = window.React;

/**
* A simple routing component that renders the appropriate
* fixture based on the location pathname.
Expand Down Expand Up @@ -41,4 +42,4 @@ function FixturesPage() {
}
}

module.exports = FixturesPage;
export default FixturesPage;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const React = window.React;

import Fixture from '../../Fixture';

const React = window.React;

class NumberInputDecimal extends React.Component {
state = {value: '.98'};
changeValue = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const React = window.React;

import Fixture from '../../Fixture';

const React = window.React;

class NumberInputExtraZeroes extends React.Component {
state = {value: '3.0000'};
changeValue = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const React = window.React;

import Fixture from '../../Fixture';

const React = window.React;

class NumberTestCase extends React.Component {
state = {value: ''};
onChange = event => {
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/components/fixtures/number-inputs/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const React = window.React;

import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';
import NumberTestCase from './NumberTestCase';
import NumberInputDecimal from './NumberInputDecimal';
import NumberInputExtraZeroes from './NumberInputExtraZeroes';

const React = window.React;

function NumberInputs() {
return (
<FixtureSet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const React = window.React;

import Fixture from '../../Fixture';

const React = window.React;

class PasswordTestCase extends React.Component {
state = {value: ''};
onChange = event => {
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/components/fixtures/password-inputs/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const React = window.React;

import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';
import PasswordTestCase from './PasswordTestCase';

const React = window.React;

function NumberInputs() {
return (
<FixtureSet title="Password inputs" description="">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const React = window.React;

import Fixture from '../../Fixture';
const React = window.React;

class InputTestCase extends React.Component {
static defaultProps = {
Expand Down
6 changes: 3 additions & 3 deletions fixtures/dom/src/components/fixtures/text-inputs/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const React = window.React;

import Fixture from '../../Fixture';
import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';
import InputTestCase from './InputTestCase';

const React = window.React;

class TextInputFixtures extends React.Component {
render() {
return (
Expand Down Expand Up @@ -93,4 +93,4 @@ class TextInputFixtures extends React.Component {
}
}

module.exports = TextInputFixtures;
export default TextInputFixtures;
14 changes: 10 additions & 4 deletions fixtures/dom/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const React = window.React;
const ReactDOM = window.ReactDOM;
import App from './components/App';
import './polyfills';
import loadReact from './react-loader';

ReactDOM.render(<App />, document.getElementById('root'));
loadReact().then(() => import('./components/App')).then(App => {
const {React, ReactDOM} = window;

ReactDOM.render(
React.createElement(App.default),
document.getElementById('root')
);
});
35 changes: 35 additions & 0 deletions fixtures/dom/src/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'core-js/es6/promise';
import 'core-js/es6/set';
import 'core-js/es6/map';

// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame =
window[vendors[x] + 'CancelAnimationFrame'] ||
window[vendors[x] + 'CancelRequestAnimationFrame'];
}

if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};

if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
})();
63 changes: 63 additions & 0 deletions fixtures/dom/src/react-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Take a version from the window query string and load a specific
* version of React.
*
* @example
* http://localhost:3000?version=15.4.1
* (Loads React 15.4.1)
*/

function parseQuery(qstr) {
var query = {};
var a = qstr.substr(1).split('&');

for (var i = 0; i < a.length; i++) {
var b = a[i].split('=');
query[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
}
return query;
}

function loadScript(src) {
let firstScript = document.getElementsByTagName('script')[0];
let scriptNode;

return new Promise((resolve, reject) => {
scriptNode = document.createElement('script');
scriptNode.async = 1;
scriptNode.src = src;

scriptNode.onload = () => resolve();
scriptNode.onerror = () => reject(new Error(`failed to load: ${src}`));

firstScript.parentNode.insertBefore(scriptNode, firstScript);
});
}

export default function loadReact() {
let REACT_PATH = 'react.development.js';
let DOM_PATH = 'react-dom.development.js';

let query = parseQuery(window.location.search);
let version = query.version || 'local';

if (version !== 'local') {
REACT_PATH = 'https://unpkg.com/react@' + version + '/dist/react.js';
DOM_PATH = 'https://unpkg.com/react-dom@' + version + '/dist/react-dom.js';
}

const needsReactDOM = version === 'local' || parseFloat(version, 10) > 0.13;

let request = loadScript(REACT_PATH);

if (needsReactDOM) {
request = request.then(() => loadScript(DOM_PATH));
} else {
// Aliasing React to ReactDOM for compatibility.
request = request.then(() => {
window.ReactDOM = window.React;
});
}

return request;
}
2 changes: 1 addition & 1 deletion fixtures/dom/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ core-js@^1.0.0:
version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"

core-js@^2.4.0:
core-js@^2.4.0, core-js@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e"

Expand Down
Loading

0 comments on commit 0b220d0

Please sign in to comment.