mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Warn on missing Set/Map polyfills (#10356)
* Crash on missing Set/Map polyfills * Change Map/Set to emit warnings instead * Change rAF polyfill check to also be a warning * Liiiiiint
This commit is contained in:
@@ -62,6 +62,22 @@ if (__DEV__) {
|
||||
var warning = require('fbjs/lib/warning');
|
||||
var validateDOMNesting = require('validateDOMNesting');
|
||||
var {updatedAncestorInfo} = validateDOMNesting;
|
||||
|
||||
if (
|
||||
typeof Map !== 'function' ||
|
||||
Map.prototype == null ||
|
||||
typeof Map.prototype.forEach !== 'function' ||
|
||||
typeof Set !== 'function' ||
|
||||
Set.prototype == null ||
|
||||
typeof Set.prototype.clear !== 'function' ||
|
||||
typeof Set.prototype.forEach !== 'function'
|
||||
) {
|
||||
warning(
|
||||
false,
|
||||
'React depends on Map and Set built-in types. Make sure that you load a ' +
|
||||
'polyfill in older browsers. http://fb.me/react-polyfills',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
require('ReactDOMClientInjection');
|
||||
|
||||
@@ -22,9 +22,23 @@
|
||||
|
||||
import type {Deadline} from 'ReactFiberReconciler';
|
||||
|
||||
var invariant = require('fbjs/lib/invariant');
|
||||
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;
|
||||
|
||||
@@ -39,12 +53,6 @@ if (!ExecutionEnvironment.canUseDOM) {
|
||||
});
|
||||
return 0;
|
||||
};
|
||||
} else if (typeof requestAnimationFrame !== 'function') {
|
||||
invariant(
|
||||
false,
|
||||
'React depends on requestAnimationFrame. Make sure that you load a ' +
|
||||
'polyfill in older browsers.',
|
||||
);
|
||||
} else if (typeof requestIdleCallback !== 'function') {
|
||||
// Polyfill requestIdleCallback.
|
||||
|
||||
|
||||
@@ -15,16 +15,16 @@ const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
|
||||
const describeFiber = ReactDOMFeatureFlags.useFiber ? describe : xdescribe;
|
||||
|
||||
describeFiber('ReactDOMFrameScheduling', () => {
|
||||
it('throws when requestAnimationFrame is not polyfilled in the browser', () => {
|
||||
it('warns when requestAnimationFrame is not polyfilled in the browser', () => {
|
||||
const previousRAF = global.requestAnimationFrame;
|
||||
try {
|
||||
global.requestAnimationFrame = undefined;
|
||||
jest.resetModules();
|
||||
expect(() => {
|
||||
require('react-dom');
|
||||
}).toThrow(
|
||||
'React depends on requestAnimationFrame. Make sure that you load a ' +
|
||||
'polyfill in older browsers.',
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user