Skip to content

Commit 4e6cc2f

Browse files
authored
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
1 parent ffec3be commit 4e6cc2f

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

src/renderers/dom/fiber/ReactDOMFiberEntry.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ if (__DEV__) {
6262
var warning = require('fbjs/lib/warning');
6363
var validateDOMNesting = require('validateDOMNesting');
6464
var {updatedAncestorInfo} = validateDOMNesting;
65+
66+
if (
67+
typeof Map !== 'function' ||
68+
Map.prototype == null ||
69+
typeof Map.prototype.forEach !== 'function' ||
70+
typeof Set !== 'function' ||
71+
Set.prototype == null ||
72+
typeof Set.prototype.clear !== 'function' ||
73+
typeof Set.prototype.forEach !== 'function'
74+
) {
75+
warning(
76+
false,
77+
'React depends on Map and Set built-in types. Make sure that you load a ' +
78+
'polyfill in older browsers. http://fb.me/react-polyfills',
79+
);
80+
}
6581
}
6682

6783
require('ReactDOMClientInjection');

src/renderers/shared/ReactDOMFrameScheduling.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,23 @@
2222

2323
import type {Deadline} from 'ReactFiberReconciler';
2424

25-
var invariant = require('fbjs/lib/invariant');
2625
var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
2726

27+
if (__DEV__) {
28+
var warning = require('fbjs/lib/warning');
29+
30+
if (
31+
ExecutionEnvironment.canUseDOM &&
32+
typeof requestAnimationFrame !== 'function'
33+
) {
34+
warning(
35+
false,
36+
'React depends on requestAnimationFrame. Make sure that you load a ' +
37+
'polyfill in older browsers. http://fb.me/react-polyfills',
38+
);
39+
}
40+
}
41+
2842
// TODO: There's no way to cancel, because Fiber doesn't atm.
2943
let rIC: (callback: (deadline: Deadline) => void) => number;
3044

@@ -39,12 +53,6 @@ if (!ExecutionEnvironment.canUseDOM) {
3953
});
4054
return 0;
4155
};
42-
} else if (typeof requestAnimationFrame !== 'function') {
43-
invariant(
44-
false,
45-
'React depends on requestAnimationFrame. Make sure that you load a ' +
46-
'polyfill in older browsers.',
47-
);
4856
} else if (typeof requestIdleCallback !== 'function') {
4957
// Polyfill requestIdleCallback.
5058

src/renderers/shared/__tests__/ReactDOMFrameScheduling-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
1515
const describeFiber = ReactDOMFeatureFlags.useFiber ? describe : xdescribe;
1616

1717
describeFiber('ReactDOMFrameScheduling', () => {
18-
it('throws when requestAnimationFrame is not polyfilled in the browser', () => {
18+
it('warns when requestAnimationFrame is not polyfilled in the browser', () => {
1919
const previousRAF = global.requestAnimationFrame;
2020
try {
2121
global.requestAnimationFrame = undefined;
2222
jest.resetModules();
23-
expect(() => {
24-
require('react-dom');
25-
}).toThrow(
26-
'React depends on requestAnimationFrame. Make sure that you load a ' +
27-
'polyfill in older browsers.',
23+
spyOn(console, 'error');
24+
require('react-dom');
25+
expect(console.error.calls.count()).toBe(1);
26+
expect(console.error.calls.argsFor(0)[0]).toContain(
27+
'React depends on requestAnimationFrame.',
2828
);
2929
} finally {
3030
global.requestAnimationFrame = previousRAF;

0 commit comments

Comments
 (0)