From 2a8085980f5a96fa33bf12d8fd78594a3baecccb Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Wed, 13 Jun 2018 10:57:35 -0700 Subject: [PATCH] Remove rAF fork (#12980) * Remove rAF fork **what is the change?:** Undid https://github.com/facebook/react/pull/12837 **why make this change?:** We originally forked rAF because we needed to pull in a particular version of rAF internally at Facebook, to avoid grabbing the default polyfilled version. The longer term solution, until we can get rid of the global polyfill behavior, is to initialize 'schedule' before the polyfilling happens. Now that we have landed and synced https://github.com/facebook/react/pull/12900 successfully, we can initialize 'schedule' before the polyfill runs. So we can remove the rAF fork. Here is how it will work: 1. Land this PR on Github. 2. Flarnie will quickly run a sync getting this change into www. 3. We delete the internal forked version of 'requestAnimationFrameForReact'. 4. We require 'schedule' in the polyfill file itself, before the polyfilling happens. **test plan:** Flarnie will manually try the above steps locally and verify that things work. **issue:** Internal task T29442940 * fix nits * fix tests, fix changes from rebasing * fix lint --- .../react-dom/src/__tests__/ReactDOM-test.js | 2 +- .../react-scheduler/src/ReactScheduler.js | 38 ++++++++----------- .../__tests__/ReactDOMFrameScheduling-test.js | 2 +- .../requestAnimationFrameForReact.www.js | 10 ----- .../shared/requestAnimationFrameForReact.js | 24 ------------ scripts/rollup/forks.js | 12 ------ 6 files changed, 18 insertions(+), 70 deletions(-) delete mode 100644 packages/shared/forks/requestAnimationFrameForReact.www.js delete mode 100644 packages/shared/requestAnimationFrameForReact.js diff --git a/packages/react-dom/src/__tests__/ReactDOM-test.js b/packages/react-dom/src/__tests__/ReactDOM-test.js index 48609a2c25..8c21143d52 100644 --- a/packages/react-dom/src/__tests__/ReactDOM-test.js +++ b/packages/react-dom/src/__tests__/ReactDOM-test.js @@ -440,7 +440,7 @@ describe('ReactDOM', () => { global.requestAnimationFrame = undefined; jest.resetModules(); expect(() => require('react-dom')).toWarnDev( - 'React depends on requestAnimationFrame.', + "This browser doesn't support requestAnimationFrame.", ); } finally { global.requestAnimationFrame = previousRAF; diff --git a/packages/react-scheduler/src/ReactScheduler.js b/packages/react-scheduler/src/ReactScheduler.js index afd0592cc9..b8f9155995 100644 --- a/packages/react-scheduler/src/ReactScheduler.js +++ b/packages/react-scheduler/src/ReactScheduler.js @@ -41,11 +41,24 @@ type CallbackConfigType = {| export type CallbackIdType = CallbackConfigType; -import requestAnimationFrameForReact from 'shared/requestAnimationFrameForReact'; import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment'; -import invariant from 'fbjs/lib/invariant'; import warning from 'fbjs/lib/warning'; +if (__DEV__) { + if ( + ExecutionEnvironment.canUseDOM && + typeof requestAnimationFrame !== 'function' + ) { + warning( + false, + // TODO: reword this when schedule is a stand-alone module + "This browser doesn't support requestAnimationFrame. " + + 'Make sure that you load a ' + + 'polyfill in older browsers. https://fb.me/react-polyfills', + ); + } +} + // We capture a local reference to any global, in case it gets polyfilled after // this module is initially evaluated. // We want to be using a consistent implementation. @@ -106,26 +119,7 @@ if (!ExecutionEnvironment.canUseDOM) { localClearTimeout(timeoutId); }; } else { - if (__DEV__) { - if (typeof requestAnimationFrameForReact !== 'function') { - warning( - false, - 'React depends on requestAnimationFrame. Make sure that you load a ' + - 'polyfill in older browsers. https://fb.me/react-polyfills', - ); - } - } - - let localRequestAnimationFrame = - typeof requestAnimationFrameForReact === 'function' - ? requestAnimationFrameForReact - : function(callback: Function) { - invariant( - false, - 'React depends on requestAnimationFrame. Make sure that you load a ' + - 'polyfill in older browsers. https://fb.me/react-polyfills', - ); - }; + const localRequestAnimationFrame = requestAnimationFrame; let headOfPendingCallbacksLinkedList: CallbackConfigType | null = null; let tailOfPendingCallbacksLinkedList: CallbackConfigType | null = null; diff --git a/packages/shared/__tests__/ReactDOMFrameScheduling-test.js b/packages/shared/__tests__/ReactDOMFrameScheduling-test.js index ff7a3d5a91..68dfdbfa14 100644 --- a/packages/shared/__tests__/ReactDOMFrameScheduling-test.js +++ b/packages/shared/__tests__/ReactDOMFrameScheduling-test.js @@ -16,7 +16,7 @@ describe('ReactDOMFrameScheduling', () => { global.requestAnimationFrame = undefined; jest.resetModules(); expect(() => require('react-dom')).toWarnDev( - 'React depends on requestAnimationFrame.', + "This browser doesn't support requestAnimationFrame.", ); } finally { global.requestAnimationFrame = previousRAF; diff --git a/packages/shared/forks/requestAnimationFrameForReact.www.js b/packages/shared/forks/requestAnimationFrameForReact.www.js deleted file mode 100644 index f082644eca..0000000000 --- a/packages/shared/forks/requestAnimationFrameForReact.www.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -'use strict'; - -export default require('requestAnimationFrameForReact'); diff --git a/packages/shared/requestAnimationFrameForReact.js b/packages/shared/requestAnimationFrameForReact.js deleted file mode 100644 index 91a584e94b..0000000000 --- a/packages/shared/requestAnimationFrameForReact.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -'use strict'; - -// We capture a local reference to any global, in case it gets polyfilled after -// this module is initially evaluated. -// We want to be using a consistent implementation. -const localRequestAnimationFrame = - typeof requestAnimationFrame === 'function' - ? requestAnimationFrame - : undefined; - -// The callsites should check if the requestAnimationFrame imported from this module is a function, -// fire a developer warning if it doesn't exist, and substitute it by a shim in that case -// (e.g. that throws on call). - -export default localRequestAnimationFrame; diff --git a/scripts/rollup/forks.js b/scripts/rollup/forks.js index ed047100a0..4c9802b369 100644 --- a/scripts/rollup/forks.js +++ b/scripts/rollup/forks.js @@ -81,18 +81,6 @@ const forks = Object.freeze({ return null; }, - // This logic is forked on www to use the 'acrossTransitions' version. - // This will be removed soon, see internal task T29442940 - 'shared/requestAnimationFrameForReact': (bundleType, entry) => { - switch (bundleType) { - case FB_WWW_DEV: - case FB_WWW_PROD: - return 'shared/forks/requestAnimationFrameForReact.www.js'; - default: - return null; - } - }, - 'shared/ReactScheduler': (bundleType, entry) => { switch (bundleType) { case FB_WWW_DEV: