@samitouri / QOS-React / commits / 4e6cc2f495

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

Dan Abramov committed Aug 2, 2017 at 18:55 UTC 4e6cc2f495db407269380badba6ca2caa167e30b
3 files changed +37 -13
src/renderers/dom/fiber/ReactDOMFiberEntry.js
+16
@@ -62,6 +62,22 @@ if (__DEV__) {
62 var warning = require('fbjs/lib/warning');
63 var validateDOMNesting = require('validateDOMNesting');
64 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 + }
81 }
82
83 require('ReactDOMClientInjection');
src/renderers/shared/ReactDOMFrameScheduling.js
+15 -7
@@ -22,9 +22,23 @@
22
23 import type {Deadline} from 'ReactFiberReconciler';
24
25 -var invariant = require('fbjs/lib/invariant');
25 var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
26
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 +
42 // TODO: There's no way to cancel, because Fiber doesn't atm.
43 let rIC: (callback: (deadline: Deadline) => void) => number;
44
@@ -39,12 +53,6 @@ if (!ExecutionEnvironment.canUseDOM) {
53 });
54 return 0;
55 };
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 - );
56 } else if (typeof requestIdleCallback !== 'function') {
57 // Polyfill requestIdleCallback.
58
src/renderers/shared/__tests__/ReactDOMFrameScheduling-test.js
+6 -6
@@ -15,16 +15,16 @@ const ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
15 const describeFiber = ReactDOMFeatureFlags.useFiber ? describe : xdescribe;
16
17 describeFiber('ReactDOMFrameScheduling', () => {
18 - it('throws when requestAnimationFrame is not polyfilled in the browser', () => {
18 + it('warns when requestAnimationFrame is not polyfilled in the browser', () => {
19 const previousRAF = global.requestAnimationFrame;
20 try {
21 global.requestAnimationFrame = undefined;
22 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.',
28 );
29 } finally {
30 global.requestAnimationFrame = previousRAF;