Skip to content

Commit

Permalink
Move RAF check to first render()
Browse files Browse the repository at this point in the history
fixes #11114
  • Loading branch information
jquense committed Oct 5, 2017
1 parent 7d3b44b commit 793a87e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
19 changes: 19 additions & 0 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,29 @@ var {
} = ReactDOMFiberComponent;
var {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;

let checkForRAF = () => {};

if (__DEV__) {
var lowPriorityWarning = require('lowPriorityWarning');
var warning = require('fbjs/lib/warning');
var validateDOMNesting = require('validateDOMNesting');
var {updatedAncestorInfo} = validateDOMNesting;
var checkedRaf = false;

checkForRAF = () => {
if (
!checkedRaf &&
ExecutionEnvironment.canUseDOM &&
typeof requestAnimationFrame !== 'function'
) {
warning(
false,
'React depends on requestAnimationFrame. Make sure that you load a ' +
'polyfill in older browsers. http://fb.me/react-polyfills',
);
}
checkedRaf = true;
};

if (
typeof Map !== 'function' ||
Expand Down Expand Up @@ -731,6 +749,7 @@ var ReactDOMFiber = {
container: DOMContainer,
callback: ?Function,
) {
checkForRAF();
return renderSubtreeIntoContainer(
null,
element,
Expand Down
20 changes: 19 additions & 1 deletion src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
'use strict';

var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-dom/test-utils');
var PropTypes = require('prop-types');

Expand All @@ -20,11 +19,30 @@ describe('ReactDOMFiber', () => {
}

var container;
var ReactDOM;

beforeEach(() => {
ReactDOM = require('react-dom');
container = document.createElement('div');
});

it('warns when requestAnimationFrame is not polyfilled in the browser', () => {
const previousRAF = global.requestAnimationFrame;
try {
global.requestAnimationFrame = undefined;
spyOn(console, 'error');

ReactDOM.render(<div />, container);

expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'React depends on requestAnimationFrame.',
);
} finally {
global.requestAnimationFrame = previousRAF;
}
});

it('should render strings as children', () => {
const Box = ({value}) => <div>{value}</div>;

Expand Down
15 changes: 0 additions & 15 deletions src/renderers/shared/ReactDOMFrameScheduling.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ import type {Deadline} from 'ReactFiberReconciler';

var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');

if (__DEV__) {
var warning = require('fbjs/lib/warning');

if (
ExecutionEnvironment.canUseDOM &&
typeof requestAnimationFrame !== 'function'
) {
warning(
false,
'React depends on requestAnimationFrame. Make sure that you load a ' +
'polyfill in older browsers. http://fb.me/react-polyfills',
);
}
}

// TODO: There's no way to cancel, because Fiber doesn't atm.
let rIC: (callback: (deadline: Deadline) => void) => number;

Expand Down
16 changes: 0 additions & 16 deletions src/renderers/shared/__tests__/ReactDOMFrameScheduling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@
'use strict';

describe('ReactDOMFrameScheduling', () => {
it('warns when requestAnimationFrame is not polyfilled in the browser', () => {
const previousRAF = global.requestAnimationFrame;
try {
global.requestAnimationFrame = undefined;
jest.resetModules();
spyOn(console, 'error');
require('react-dom');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'React depends on requestAnimationFrame.',
);
} finally {
global.requestAnimationFrame = previousRAF;
}
});

// We're just testing importing, not using it.
// It is important because even isomorphic components may import it.
it('can import findDOMNode in Node environment', () => {
Expand Down

0 comments on commit 793a87e

Please sign in to comment.