@samitouri / QOS-React / commits / 835c21a5ef

Don't prevent extensions on Fiber if using bad Map polyfill (#9572)

Many Map polyfills work by adding an extra field to the key type. In the future, we'll likely print a warning.

Andrew Clark committed May 1, 2017 at 13:23 UTC 835c21a5ef52a2f29180c4ffc046bebb14d07eb3
1 file changed +13 -1
src/renderers/shared/fiber/ReactFiber.js
+13 -1
@@ -49,6 +49,18 @@ var invariant = require('fbjs/lib/invariant');
49
50 if (__DEV__) {
51 var getComponentName = require('getComponentName');
52 +
53 + var hasBadMapPolyfill = false;
54 + try {
55 + const nonExtensibleObject = Object.preventExtensions({});
56 + /* eslint-disable no-new */
57 + new Map([[nonExtensibleObject, null]]);
58 + new Set([nonExtensibleObject]);
59 + /* eslint-enable no-new */
60 + } catch (e) {
61 + // TODO: Consider warning about bad polyfills
62 + hasBadMapPolyfill = true;
63 + }
64 }
65
66 // A Fiber is work on a Component that needs to be done or was done. There can
@@ -234,7 +246,7 @@ var createFiber = function(
246 fiber._debugSource = null;
247 fiber._debugOwner = null;
248 fiber._debugIsCurrentlyTiming = false;
237 - if (typeof Object.preventExtensions === 'function') {
249 + if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') {
250 Object.preventExtensions(fiber);
251 }
252 }