From 85a4ccb320defc44ce3e3316063100559c690979 Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Fri, 29 Jun 2018 23:08:37 -0400 Subject: [PATCH 1/9] [#13130] Add a more helpful message when passing an element to createElement() --- packages/react/src/ReactElementValidator.js | 5 + scripts/rollup/results.json | 337 +++++++++++--------- 2 files changed, 184 insertions(+), 158 deletions(-) diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index f0ea9601b8a37..3dc225d9b2d57 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -329,8 +329,13 @@ export function createElementWithValidation(type, props, children) { let typeString; if (type === null) { typeString = 'null'; + } else if (type === undefined) { + typeString = 'undefined'; } else if (Array.isArray(type)) { typeString = 'array'; + } else if (type.$$typeof) { + typeString = 'element'; + info = ' Did you accidentally export JSX instead of a component?'; } else { typeString = typeof type; } diff --git a/scripts/rollup/results.json b/scripts/rollup/results.json index ea7d1c4e07de1..4724132307b44 100644 --- a/scripts/rollup/results.json +++ b/scripts/rollup/results.json @@ -4,29 +4,29 @@ "filename": "react.development.js", "bundleType": "UMD_DEV", "packageName": "react", - "size": 59086, - "gzip": 16296 + "size": 58314, + "gzip": 16232 }, { "filename": "react.production.min.js", "bundleType": "UMD_PROD", "packageName": "react", - "size": 7217, - "gzip": 3050 + "size": 7024, + "gzip": 2981 }, { "filename": "react.development.js", "bundleType": "NODE_DEV", "packageName": "react", - "size": 49501, - "gzip": 13887 + "size": 52367, + "gzip": 14362 }, { "filename": "react.production.min.js", "bundleType": "NODE_PROD", "packageName": "react", - "size": 5724, - "gzip": 2481 + "size": 6003, + "gzip": 2576 }, { "filename": "React-dev.js", @@ -46,29 +46,29 @@ "filename": "react-dom.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 641505, - "gzip": 149286 + "size": 642946, + "gzip": 150373 }, { "filename": "react-dom.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 96507, - "gzip": 31258 + "size": 97923, + "gzip": 31681 }, { "filename": "react-dom.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 625496, - "gzip": 145193 + "size": 638980, + "gzip": 149169 }, { "filename": "react-dom.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 94969, - "gzip": 30225 + "size": 97915, + "gzip": 31200 }, { "filename": "ReactDOM-dev.js", @@ -88,29 +88,29 @@ "filename": "react-dom-test-utils.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 46355, - "gzip": 12768 + "size": 43999, + "gzip": 12222 }, { "filename": "react-dom-test-utils.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 10653, - "gzip": 3918 + "size": 10351, + "gzip": 3848 }, { "filename": "react-dom-test-utils.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 41092, - "gzip": 11309 + "size": 43707, + "gzip": 12155 }, { "filename": "react-dom-test-utils.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 9913, - "gzip": 3696 + "size": 10146, + "gzip": 3804 }, { "filename": "ReactTestUtils-dev.js", @@ -123,29 +123,29 @@ "filename": "react-dom-unstable-native-dependencies.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 62921, - "gzip": 16559 + "size": 61430, + "gzip": 16260 }, { "filename": "react-dom-unstable-native-dependencies.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 11622, - "gzip": 4007 + "size": 11319, + "gzip": 3915 }, { "filename": "react-dom-unstable-native-dependencies.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 58483, - "gzip": 15262 + "size": 61094, + "gzip": 16126 }, { "filename": "react-dom-unstable-native-dependencies.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 10939, - "gzip": 3744 + "size": 11135, + "gzip": 3837 }, { "filename": "ReactDOMUnstableNativeDependencies-dev.js", @@ -165,29 +165,29 @@ "filename": "react-dom-server.browser.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 105006, - "gzip": 27524 + "size": 101652, + "gzip": 26861 }, { "filename": "react-dom-server.browser.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 15463, - "gzip": 5917 + "size": 15167, + "gzip": 5826 }, { "filename": "react-dom-server.browser.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 94052, - "gzip": 25217 + "size": 97684, + "gzip": 25900 }, { "filename": "react-dom-server.browser.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 14810, - "gzip": 5665 + "size": 15061, + "gzip": 5756 }, { "filename": "ReactDOMServer-dev.js", @@ -207,43 +207,43 @@ "filename": "react-dom-server.node.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 96020, - "gzip": 25767 + "size": 99652, + "gzip": 26449 }, { "filename": "react-dom-server.node.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 15634, - "gzip": 5964 + "size": 15885, + "gzip": 6065 }, { "filename": "react-art.development.js", "bundleType": "UMD_DEV", "packageName": "react-art", - "size": 417844, - "gzip": 93214 + "size": 421747, + "gzip": 94628 }, { "filename": "react-art.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-art", - "size": 83064, - "gzip": 25615 + "size": 84760, + "gzip": 26137 }, { "filename": "react-art.development.js", "bundleType": "NODE_DEV", "packageName": "react-art", - "size": 341917, - "gzip": 73846 + "size": 352093, + "gzip": 77079 }, { "filename": "react-art.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-art", - "size": 46568, - "gzip": 14504 + "size": 48901, + "gzip": 15265 }, { "filename": "ReactART-dev.js", @@ -291,29 +291,29 @@ "filename": "react-test-renderer.development.js", "bundleType": "UMD_DEV", "packageName": "react-test-renderer", - "size": 349236, - "gzip": 75574 + "size": 356713, + "gzip": 77648 }, { "filename": "react-test-renderer.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-test-renderer", - "size": 47024, - "gzip": 14562 + "size": 49810, + "gzip": 15329 }, { "filename": "react-test-renderer.development.js", "bundleType": "NODE_DEV", "packageName": "react-test-renderer", - "size": 339847, - "gzip": 72777 + "size": 352740, + "gzip": 76642 }, { "filename": "react-test-renderer.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-test-renderer", - "size": 46110, - "gzip": 14094 + "size": 49514, + "gzip": 15138 }, { "filename": "ReactTestRenderer-dev.js", @@ -326,29 +326,29 @@ "filename": "react-test-renderer-shallow.development.js", "bundleType": "UMD_DEV", "packageName": "react-test-renderer", - "size": 24945, - "gzip": 6660 + "size": 22155, + "gzip": 6045 }, { "filename": "react-test-renderer-shallow.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-test-renderer", - "size": 7320, - "gzip": 2398 + "size": 7327, + "gzip": 2395 }, { "filename": "react-test-renderer-shallow.development.js", "bundleType": "NODE_DEV", "packageName": "react-test-renderer", - "size": 14751, - "gzip": 3694 + "size": 17231, + "gzip": 4716 }, { "filename": "react-test-renderer-shallow.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-test-renderer", - "size": 7363, - "gzip": 2403 + "size": 7961, + "gzip": 2642 }, { "filename": "ReactShallowRenderer-dev.js", @@ -361,57 +361,57 @@ "filename": "react-noop-renderer.development.js", "bundleType": "NODE_DEV", "packageName": "react-noop-renderer", - "size": 18358, - "gzip": 4804 + "size": 18502, + "gzip": 4836 }, { "filename": "react-noop-renderer.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-noop-renderer", - "size": 6829, - "gzip": 2631 + "size": 6866, + "gzip": 2640 }, { "filename": "react-reconciler.development.js", "bundleType": "NODE_DEV", "packageName": "react-reconciler", - "size": 331893, - "gzip": 70268 + "size": 341158, + "gzip": 73106 }, { "filename": "react-reconciler.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-reconciler", - "size": 46230, - "gzip": 13812 + "size": 48409, + "gzip": 14554 }, { "filename": "react-reconciler-persistent.development.js", "bundleType": "NODE_DEV", "packageName": "react-reconciler", - "size": 330477, - "gzip": 69672 + "size": 339741, + "gzip": 72528 }, { "filename": "react-reconciler-persistent.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-reconciler", - "size": 46241, - "gzip": 13818 + "size": 48420, + "gzip": 14560 }, { "filename": "react-reconciler-reflection.development.js", "bundleType": "NODE_DEV", "packageName": "react-reconciler", - "size": 11847, - "gzip": 3642 + "size": 14424, + "gzip": 4540 }, { "filename": "react-reconciler-reflection.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-reconciler", - "size": 2312, - "gzip": 1027 + "size": 2608, + "gzip": 1152 }, { "filename": "react-call-return.development.js", @@ -473,8 +473,8 @@ "filename": "simple-cache-provider.development.js", "bundleType": "NODE_DEV", "packageName": "simple-cache-provider", - "size": 7654, - "gzip": 2412 + "size": 9075, + "gzip": 2932 }, { "filename": "simple-cache-provider.production.min.js", @@ -487,162 +487,162 @@ "filename": "create-subscription.development.js", "bundleType": "NODE_DEV", "packageName": "create-subscription", - "size": 5636, - "gzip": 1973 + "size": 8215, + "gzip": 2846 }, { "filename": "create-subscription.production.min.js", "bundleType": "NODE_PROD", "packageName": "create-subscription", - "size": 2591, - "gzip": 1233 + "size": 2891, + "gzip": 1350 }, { "filename": "React-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react", - "size": 49728, - "gzip": 13583 + "size": 49884, + "gzip": 13615 }, { "filename": "React-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react", - "size": 13708, - "gzip": 3835 + "size": 13703, + "gzip": 3817 }, { "filename": "ReactDOM-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 634902, - "gzip": 144512 + "size": 645122, + "gzip": 147396 }, { "filename": "ReactDOM-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-dom", - "size": 275897, - "gzip": 51771 + "size": 275258, + "gzip": 51916 }, { "filename": "ReactTestUtils-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 42513, - "gzip": 11507 + "size": 42538, + "gzip": 11515 }, { "filename": "ReactDOMUnstableNativeDependencies-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 58699, - "gzip": 15042 + "size": 58702, + "gzip": 15038 }, { "filename": "ReactDOMUnstableNativeDependencies-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-dom", - "size": 26877, - "gzip": 5467 + "size": 26839, + "gzip": 5451 }, { "filename": "ReactDOMServer-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 97859, - "gzip": 25094 + "size": 98766, + "gzip": 25426 }, { "filename": "ReactDOMServer-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-dom", - "size": 32295, - "gzip": 7922 + "size": 32740, + "gzip": 7971 }, { "filename": "ReactART-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-art", - "size": 334032, - "gzip": 69646 + "size": 340627, + "gzip": 71690 }, { "filename": "ReactART-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-art", - "size": 145574, - "gzip": 24830 + "size": 143027, + "gzip": 24578 }, { "filename": "ReactNativeRenderer-dev.js", "bundleType": "RN_FB_DEV", "packageName": "react-native-renderer", - "size": 468596, - "gzip": 102411 + "size": 478042, + "gzip": 105260 }, { "filename": "ReactNativeRenderer-prod.js", "bundleType": "RN_FB_PROD", "packageName": "react-native-renderer", - "size": 210858, - "gzip": 36787 + "size": 208382, + "gzip": 36601 }, { "filename": "ReactNativeRenderer-dev.js", "bundleType": "RN_OSS_DEV", "packageName": "react-native-renderer", - "size": 468299, - "gzip": 102347 + "size": 477769, + "gzip": 105199 }, { "filename": "ReactNativeRenderer-prod.js", "bundleType": "RN_OSS_PROD", "packageName": "react-native-renderer", - "size": 198778, - "gzip": 34759 + "size": 204402, + "gzip": 35824 }, { "filename": "ReactFabric-dev.js", "bundleType": "RN_FB_DEV", "packageName": "react-native-renderer", - "size": 459344, - "gzip": 100124 + "size": 468086, + "gzip": 102794 }, { "filename": "ReactFabric-prod.js", "bundleType": "RN_FB_PROD", "packageName": "react-native-renderer", - "size": 190842, - "gzip": 33372 + "size": 196473, + "gzip": 34372 }, { "filename": "ReactFabric-dev.js", "bundleType": "RN_OSS_DEV", "packageName": "react-native-renderer", - "size": 459380, - "gzip": 100141 + "size": 468122, + "gzip": 102811 }, { "filename": "ReactFabric-prod.js", "bundleType": "RN_OSS_PROD", "packageName": "react-native-renderer", - "size": 190878, - "gzip": 33392 + "size": 196509, + "gzip": 34388 }, { "filename": "ReactTestRenderer-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-test-renderer", - "size": 345831, - "gzip": 72349 + "size": 356038, + "gzip": 75348 }, { "filename": "ReactShallowRenderer-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-test-renderer", - "size": 15507, - "gzip": 3819 + "size": 16855, + "gzip": 4397 }, { "filename": "ReactIs-dev.js", @@ -662,92 +662,113 @@ "filename": "react-scheduler.development.js", "bundleType": "UMD_DEV", "packageName": "react-scheduler", - "size": 19628, - "gzip": 5881 + "size": 16696, + "gzip": 5194 }, { "filename": "react-scheduler.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-scheduler", - "size": 3233, - "gzip": 1562 + "size": 2687, + "gzip": 1273 }, { "filename": "react-scheduler.development.js", "bundleType": "NODE_DEV", "packageName": "react-scheduler", - "size": 14449, - "gzip": 4354 + "size": 16500, + "gzip": 5148 }, { "filename": "react-scheduler.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-scheduler", - "size": 2825, - "gzip": 1387 + "size": 2604, + "gzip": 1220 }, { "filename": "SimpleCacheProvider-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "simple-cache-provider", - "size": 8054, - "gzip": 2450 + "size": 8046, + "gzip": 2442 }, { "filename": "SimpleCacheProvider-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "simple-cache-provider", - "size": 3714, - "gzip": 1127 + "size": 3734, + "gzip": 1137 }, { "filename": "react-noop-renderer-persistent.development.js", "bundleType": "NODE_DEV", "packageName": "react-noop-renderer", - "size": 18487, - "gzip": 4818 + "size": 18631, + "gzip": 4854 }, { "filename": "react-noop-renderer-persistent.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-noop-renderer", - "size": 6851, - "gzip": 2637 + "size": 6888, + "gzip": 2646 }, { "filename": "react-dom.profiling.min.js", "bundleType": "NODE_PROFILING", "packageName": "react-dom", - "size": 95896, - "gzip": 30574 + "size": 98912, + "gzip": 31554 }, { "filename": "ReactNativeRenderer-profiling.js", "bundleType": "RN_OSS_PROFILING", "packageName": "react-native-renderer", - "size": 201375, - "gzip": 35312 + "size": 207140, + "gzip": 36438 }, { "filename": "ReactFabric-profiling.js", "bundleType": "RN_OSS_PROFILING", "packageName": "react-native-renderer", - "size": 193150, - "gzip": 33867 + "size": 198922, + "gzip": 34917 }, { "filename": "ReactScheduler-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-scheduler", - "size": 14452, - "gzip": 4364 + "size": 15229, + "gzip": 4664 }, { "filename": "ReactScheduler-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-scheduler", - "size": 7800, - "gzip": 2108 + "size": 7648, + "gzip": 1945 + }, + { + "filename": "ReactDOM-profiling.js", + "bundleType": "FB_WWW_PROFILING", + "packageName": "react-dom", + "size": 277941, + "gzip": 52504 + }, + { + "filename": "ReactNativeRenderer-profiling.js", + "bundleType": "RN_FB_PROFILING", + "packageName": "react-native-renderer", + "size": 211082, + "gzip": 37216 + }, + { + "filename": "ReactFabric-profiling.js", + "bundleType": "RN_FB_PROFILING", + "packageName": "react-native-renderer", + "size": 198881, + "gzip": 34899 } ] } \ No newline at end of file From 24a071fa8f6e4344eafcbdd20dec979c71491513 Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Sat, 30 Jun 2018 01:24:29 -0400 Subject: [PATCH 2/9] better conditional flow --- packages/react/src/ReactElementValidator.js | 10 +- scripts/rollup/results.json | 337 +++++++++----------- 2 files changed, 162 insertions(+), 185 deletions(-) diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index 3dc225d9b2d57..91b3990aa8e26 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -327,15 +327,13 @@ export function createElementWithValidation(type, props, children) { info += getStackAddendum() || ''; let typeString; - if (type === null) { + if (type && type.$$typeof) { + typeString = 'element'; + info = ' Did you accidentally export JSX instead of a component?'; + } else if (type === null) { typeString = 'null'; - } else if (type === undefined) { - typeString = 'undefined'; } else if (Array.isArray(type)) { typeString = 'array'; - } else if (type.$$typeof) { - typeString = 'element'; - info = ' Did you accidentally export JSX instead of a component?'; } else { typeString = typeof type; } diff --git a/scripts/rollup/results.json b/scripts/rollup/results.json index 4724132307b44..ea7d1c4e07de1 100644 --- a/scripts/rollup/results.json +++ b/scripts/rollup/results.json @@ -4,29 +4,29 @@ "filename": "react.development.js", "bundleType": "UMD_DEV", "packageName": "react", - "size": 58314, - "gzip": 16232 + "size": 59086, + "gzip": 16296 }, { "filename": "react.production.min.js", "bundleType": "UMD_PROD", "packageName": "react", - "size": 7024, - "gzip": 2981 + "size": 7217, + "gzip": 3050 }, { "filename": "react.development.js", "bundleType": "NODE_DEV", "packageName": "react", - "size": 52367, - "gzip": 14362 + "size": 49501, + "gzip": 13887 }, { "filename": "react.production.min.js", "bundleType": "NODE_PROD", "packageName": "react", - "size": 6003, - "gzip": 2576 + "size": 5724, + "gzip": 2481 }, { "filename": "React-dev.js", @@ -46,29 +46,29 @@ "filename": "react-dom.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 642946, - "gzip": 150373 + "size": 641505, + "gzip": 149286 }, { "filename": "react-dom.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 97923, - "gzip": 31681 + "size": 96507, + "gzip": 31258 }, { "filename": "react-dom.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 638980, - "gzip": 149169 + "size": 625496, + "gzip": 145193 }, { "filename": "react-dom.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 97915, - "gzip": 31200 + "size": 94969, + "gzip": 30225 }, { "filename": "ReactDOM-dev.js", @@ -88,29 +88,29 @@ "filename": "react-dom-test-utils.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 43999, - "gzip": 12222 + "size": 46355, + "gzip": 12768 }, { "filename": "react-dom-test-utils.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 10351, - "gzip": 3848 + "size": 10653, + "gzip": 3918 }, { "filename": "react-dom-test-utils.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 43707, - "gzip": 12155 + "size": 41092, + "gzip": 11309 }, { "filename": "react-dom-test-utils.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 10146, - "gzip": 3804 + "size": 9913, + "gzip": 3696 }, { "filename": "ReactTestUtils-dev.js", @@ -123,29 +123,29 @@ "filename": "react-dom-unstable-native-dependencies.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 61430, - "gzip": 16260 + "size": 62921, + "gzip": 16559 }, { "filename": "react-dom-unstable-native-dependencies.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 11319, - "gzip": 3915 + "size": 11622, + "gzip": 4007 }, { "filename": "react-dom-unstable-native-dependencies.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 61094, - "gzip": 16126 + "size": 58483, + "gzip": 15262 }, { "filename": "react-dom-unstable-native-dependencies.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 11135, - "gzip": 3837 + "size": 10939, + "gzip": 3744 }, { "filename": "ReactDOMUnstableNativeDependencies-dev.js", @@ -165,29 +165,29 @@ "filename": "react-dom-server.browser.development.js", "bundleType": "UMD_DEV", "packageName": "react-dom", - "size": 101652, - "gzip": 26861 + "size": 105006, + "gzip": 27524 }, { "filename": "react-dom-server.browser.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-dom", - "size": 15167, - "gzip": 5826 + "size": 15463, + "gzip": 5917 }, { "filename": "react-dom-server.browser.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 97684, - "gzip": 25900 + "size": 94052, + "gzip": 25217 }, { "filename": "react-dom-server.browser.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 15061, - "gzip": 5756 + "size": 14810, + "gzip": 5665 }, { "filename": "ReactDOMServer-dev.js", @@ -207,43 +207,43 @@ "filename": "react-dom-server.node.development.js", "bundleType": "NODE_DEV", "packageName": "react-dom", - "size": 99652, - "gzip": 26449 + "size": 96020, + "gzip": 25767 }, { "filename": "react-dom-server.node.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-dom", - "size": 15885, - "gzip": 6065 + "size": 15634, + "gzip": 5964 }, { "filename": "react-art.development.js", "bundleType": "UMD_DEV", "packageName": "react-art", - "size": 421747, - "gzip": 94628 + "size": 417844, + "gzip": 93214 }, { "filename": "react-art.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-art", - "size": 84760, - "gzip": 26137 + "size": 83064, + "gzip": 25615 }, { "filename": "react-art.development.js", "bundleType": "NODE_DEV", "packageName": "react-art", - "size": 352093, - "gzip": 77079 + "size": 341917, + "gzip": 73846 }, { "filename": "react-art.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-art", - "size": 48901, - "gzip": 15265 + "size": 46568, + "gzip": 14504 }, { "filename": "ReactART-dev.js", @@ -291,29 +291,29 @@ "filename": "react-test-renderer.development.js", "bundleType": "UMD_DEV", "packageName": "react-test-renderer", - "size": 356713, - "gzip": 77648 + "size": 349236, + "gzip": 75574 }, { "filename": "react-test-renderer.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-test-renderer", - "size": 49810, - "gzip": 15329 + "size": 47024, + "gzip": 14562 }, { "filename": "react-test-renderer.development.js", "bundleType": "NODE_DEV", "packageName": "react-test-renderer", - "size": 352740, - "gzip": 76642 + "size": 339847, + "gzip": 72777 }, { "filename": "react-test-renderer.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-test-renderer", - "size": 49514, - "gzip": 15138 + "size": 46110, + "gzip": 14094 }, { "filename": "ReactTestRenderer-dev.js", @@ -326,29 +326,29 @@ "filename": "react-test-renderer-shallow.development.js", "bundleType": "UMD_DEV", "packageName": "react-test-renderer", - "size": 22155, - "gzip": 6045 + "size": 24945, + "gzip": 6660 }, { "filename": "react-test-renderer-shallow.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-test-renderer", - "size": 7327, - "gzip": 2395 + "size": 7320, + "gzip": 2398 }, { "filename": "react-test-renderer-shallow.development.js", "bundleType": "NODE_DEV", "packageName": "react-test-renderer", - "size": 17231, - "gzip": 4716 + "size": 14751, + "gzip": 3694 }, { "filename": "react-test-renderer-shallow.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-test-renderer", - "size": 7961, - "gzip": 2642 + "size": 7363, + "gzip": 2403 }, { "filename": "ReactShallowRenderer-dev.js", @@ -361,57 +361,57 @@ "filename": "react-noop-renderer.development.js", "bundleType": "NODE_DEV", "packageName": "react-noop-renderer", - "size": 18502, - "gzip": 4836 + "size": 18358, + "gzip": 4804 }, { "filename": "react-noop-renderer.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-noop-renderer", - "size": 6866, - "gzip": 2640 + "size": 6829, + "gzip": 2631 }, { "filename": "react-reconciler.development.js", "bundleType": "NODE_DEV", "packageName": "react-reconciler", - "size": 341158, - "gzip": 73106 + "size": 331893, + "gzip": 70268 }, { "filename": "react-reconciler.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-reconciler", - "size": 48409, - "gzip": 14554 + "size": 46230, + "gzip": 13812 }, { "filename": "react-reconciler-persistent.development.js", "bundleType": "NODE_DEV", "packageName": "react-reconciler", - "size": 339741, - "gzip": 72528 + "size": 330477, + "gzip": 69672 }, { "filename": "react-reconciler-persistent.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-reconciler", - "size": 48420, - "gzip": 14560 + "size": 46241, + "gzip": 13818 }, { "filename": "react-reconciler-reflection.development.js", "bundleType": "NODE_DEV", "packageName": "react-reconciler", - "size": 14424, - "gzip": 4540 + "size": 11847, + "gzip": 3642 }, { "filename": "react-reconciler-reflection.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-reconciler", - "size": 2608, - "gzip": 1152 + "size": 2312, + "gzip": 1027 }, { "filename": "react-call-return.development.js", @@ -473,8 +473,8 @@ "filename": "simple-cache-provider.development.js", "bundleType": "NODE_DEV", "packageName": "simple-cache-provider", - "size": 9075, - "gzip": 2932 + "size": 7654, + "gzip": 2412 }, { "filename": "simple-cache-provider.production.min.js", @@ -487,162 +487,162 @@ "filename": "create-subscription.development.js", "bundleType": "NODE_DEV", "packageName": "create-subscription", - "size": 8215, - "gzip": 2846 + "size": 5636, + "gzip": 1973 }, { "filename": "create-subscription.production.min.js", "bundleType": "NODE_PROD", "packageName": "create-subscription", - "size": 2891, - "gzip": 1350 + "size": 2591, + "gzip": 1233 }, { "filename": "React-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react", - "size": 49884, - "gzip": 13615 + "size": 49728, + "gzip": 13583 }, { "filename": "React-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react", - "size": 13703, - "gzip": 3817 + "size": 13708, + "gzip": 3835 }, { "filename": "ReactDOM-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 645122, - "gzip": 147396 + "size": 634902, + "gzip": 144512 }, { "filename": "ReactDOM-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-dom", - "size": 275258, - "gzip": 51916 + "size": 275897, + "gzip": 51771 }, { "filename": "ReactTestUtils-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 42538, - "gzip": 11515 + "size": 42513, + "gzip": 11507 }, { "filename": "ReactDOMUnstableNativeDependencies-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 58702, - "gzip": 15038 + "size": 58699, + "gzip": 15042 }, { "filename": "ReactDOMUnstableNativeDependencies-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-dom", - "size": 26839, - "gzip": 5451 + "size": 26877, + "gzip": 5467 }, { "filename": "ReactDOMServer-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-dom", - "size": 98766, - "gzip": 25426 + "size": 97859, + "gzip": 25094 }, { "filename": "ReactDOMServer-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-dom", - "size": 32740, - "gzip": 7971 + "size": 32295, + "gzip": 7922 }, { "filename": "ReactART-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-art", - "size": 340627, - "gzip": 71690 + "size": 334032, + "gzip": 69646 }, { "filename": "ReactART-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-art", - "size": 143027, - "gzip": 24578 + "size": 145574, + "gzip": 24830 }, { "filename": "ReactNativeRenderer-dev.js", "bundleType": "RN_FB_DEV", "packageName": "react-native-renderer", - "size": 478042, - "gzip": 105260 + "size": 468596, + "gzip": 102411 }, { "filename": "ReactNativeRenderer-prod.js", "bundleType": "RN_FB_PROD", "packageName": "react-native-renderer", - "size": 208382, - "gzip": 36601 + "size": 210858, + "gzip": 36787 }, { "filename": "ReactNativeRenderer-dev.js", "bundleType": "RN_OSS_DEV", "packageName": "react-native-renderer", - "size": 477769, - "gzip": 105199 + "size": 468299, + "gzip": 102347 }, { "filename": "ReactNativeRenderer-prod.js", "bundleType": "RN_OSS_PROD", "packageName": "react-native-renderer", - "size": 204402, - "gzip": 35824 + "size": 198778, + "gzip": 34759 }, { "filename": "ReactFabric-dev.js", "bundleType": "RN_FB_DEV", "packageName": "react-native-renderer", - "size": 468086, - "gzip": 102794 + "size": 459344, + "gzip": 100124 }, { "filename": "ReactFabric-prod.js", "bundleType": "RN_FB_PROD", "packageName": "react-native-renderer", - "size": 196473, - "gzip": 34372 + "size": 190842, + "gzip": 33372 }, { "filename": "ReactFabric-dev.js", "bundleType": "RN_OSS_DEV", "packageName": "react-native-renderer", - "size": 468122, - "gzip": 102811 + "size": 459380, + "gzip": 100141 }, { "filename": "ReactFabric-prod.js", "bundleType": "RN_OSS_PROD", "packageName": "react-native-renderer", - "size": 196509, - "gzip": 34388 + "size": 190878, + "gzip": 33392 }, { "filename": "ReactTestRenderer-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-test-renderer", - "size": 356038, - "gzip": 75348 + "size": 345831, + "gzip": 72349 }, { "filename": "ReactShallowRenderer-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-test-renderer", - "size": 16855, - "gzip": 4397 + "size": 15507, + "gzip": 3819 }, { "filename": "ReactIs-dev.js", @@ -662,113 +662,92 @@ "filename": "react-scheduler.development.js", "bundleType": "UMD_DEV", "packageName": "react-scheduler", - "size": 16696, - "gzip": 5194 + "size": 19628, + "gzip": 5881 }, { "filename": "react-scheduler.production.min.js", "bundleType": "UMD_PROD", "packageName": "react-scheduler", - "size": 2687, - "gzip": 1273 + "size": 3233, + "gzip": 1562 }, { "filename": "react-scheduler.development.js", "bundleType": "NODE_DEV", "packageName": "react-scheduler", - "size": 16500, - "gzip": 5148 + "size": 14449, + "gzip": 4354 }, { "filename": "react-scheduler.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-scheduler", - "size": 2604, - "gzip": 1220 + "size": 2825, + "gzip": 1387 }, { "filename": "SimpleCacheProvider-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "simple-cache-provider", - "size": 8046, - "gzip": 2442 + "size": 8054, + "gzip": 2450 }, { "filename": "SimpleCacheProvider-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "simple-cache-provider", - "size": 3734, - "gzip": 1137 + "size": 3714, + "gzip": 1127 }, { "filename": "react-noop-renderer-persistent.development.js", "bundleType": "NODE_DEV", "packageName": "react-noop-renderer", - "size": 18631, - "gzip": 4854 + "size": 18487, + "gzip": 4818 }, { "filename": "react-noop-renderer-persistent.production.min.js", "bundleType": "NODE_PROD", "packageName": "react-noop-renderer", - "size": 6888, - "gzip": 2646 + "size": 6851, + "gzip": 2637 }, { "filename": "react-dom.profiling.min.js", "bundleType": "NODE_PROFILING", "packageName": "react-dom", - "size": 98912, - "gzip": 31554 + "size": 95896, + "gzip": 30574 }, { "filename": "ReactNativeRenderer-profiling.js", "bundleType": "RN_OSS_PROFILING", "packageName": "react-native-renderer", - "size": 207140, - "gzip": 36438 + "size": 201375, + "gzip": 35312 }, { "filename": "ReactFabric-profiling.js", "bundleType": "RN_OSS_PROFILING", "packageName": "react-native-renderer", - "size": 198922, - "gzip": 34917 + "size": 193150, + "gzip": 33867 }, { "filename": "ReactScheduler-dev.js", "bundleType": "FB_WWW_DEV", "packageName": "react-scheduler", - "size": 15229, - "gzip": 4664 + "size": 14452, + "gzip": 4364 }, { "filename": "ReactScheduler-prod.js", "bundleType": "FB_WWW_PROD", "packageName": "react-scheduler", - "size": 7648, - "gzip": 1945 - }, - { - "filename": "ReactDOM-profiling.js", - "bundleType": "FB_WWW_PROFILING", - "packageName": "react-dom", - "size": 277941, - "gzip": 52504 - }, - { - "filename": "ReactNativeRenderer-profiling.js", - "bundleType": "RN_FB_PROFILING", - "packageName": "react-native-renderer", - "size": 211082, - "gzip": 37216 - }, - { - "filename": "ReactFabric-profiling.js", - "bundleType": "RN_FB_PROFILING", - "packageName": "react-native-renderer", - "size": 198881, - "gzip": 34899 + "size": 7800, + "gzip": 2108 } ] } \ No newline at end of file From 4bf86b0503594346b87652c2b38ba9a4d92517a3 Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Thu, 5 Jul 2018 12:39:56 -0400 Subject: [PATCH 3/9] update after review --- packages/react/src/ReactElementValidator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index 91b3990aa8e26..d8147b900692a 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -327,13 +327,13 @@ export function createElementWithValidation(type, props, children) { info += getStackAddendum() || ''; let typeString; - if (type && type.$$typeof) { - typeString = 'element'; - info = ' Did you accidentally export JSX instead of a component?'; - } else if (type === null) { + if (type === null) { typeString = 'null'; } else if (Array.isArray(type)) { typeString = 'array'; + } else if (type && type.hasOwnProperty('$$typeof')) { + typeString = 'element'; + info = ' Did you accidentally export JSX instead of a component?'; } else { typeString = typeof type; } From eafc93c08bcd059ede2f63d4a5d123def9a5916c Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Mon, 16 Jul 2018 22:03:05 -0400 Subject: [PATCH 4/9] move last condition inside last else clause --- packages/react/src/ReactElementValidator.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index d8147b900692a..1b56ed6a264e8 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -331,11 +331,12 @@ export function createElementWithValidation(type, props, children) { typeString = 'null'; } else if (Array.isArray(type)) { typeString = 'array'; - } else if (type && type.hasOwnProperty('$$typeof')) { - typeString = 'element'; - info = ' Did you accidentally export JSX instead of a component?'; } else { typeString = typeof type; + if (type && type.hasOwnProperty('$$typeof')) { + typeString = 'element'; + info = ' Did you accidentally export JSX instead of a component?'; + } } warning( From 453455d307cab16f5ef5377ef03548e7da5472df Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Tue, 17 Jul 2018 20:22:54 -0400 Subject: [PATCH 5/9] Added test case --- .../src/__tests__/ReactElementValidator-test.internal.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index 8fca997707129..0fb5838c0be54 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -235,6 +235,7 @@ describe('ReactElementValidator', () => { React.createElement(true); React.createElement({x: 17}); React.createElement({}); + React.createElement(React.createElement('div')); }).toWarnDev([ 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + @@ -255,6 +256,10 @@ describe('ReactElementValidator', () => { 'components) but got: object. You likely forgot to export your ' + "component from the file it's defined in, or you might have mixed up " + 'default and named imports.', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: element. Did you accidentally export JSX ' + + 'instead of a component?', ]); // Should not log any additional warnings From 7d267629397fd57d246a52c8de5d1863f04b30cd Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Tue, 17 Jul 2018 23:14:11 -0400 Subject: [PATCH 6/9] compare 25132typeof to REACT_ELEMENT_TYPE --- packages/react/src/ReactElementValidator.js | 5 +- .../ReactElementValidator-test.internal.js | 57 +++++++++++-------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index 1b56ed6a264e8..01da664576120 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -20,6 +20,7 @@ import { getIteratorFn, REACT_FORWARD_REF_TYPE, REACT_FRAGMENT_TYPE, + REACT_ELEMENT_TYPE, } from 'shared/ReactSymbols'; import checkPropTypes from 'prop-types/checkPropTypes'; import warning from 'shared/warning'; @@ -333,8 +334,8 @@ export function createElementWithValidation(type, props, children) { typeString = 'array'; } else { typeString = typeof type; - if (type && type.hasOwnProperty('$$typeof')) { - typeString = 'element'; + if (type && type.$$typeof === REACT_ELEMENT_TYPE) { + typeString = 'React element'; info = ' Did you accidentally export JSX instead of a component?'; } } diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index 0fb5838c0be54..dd74dee58e665 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -236,31 +236,38 @@ describe('ReactElementValidator', () => { React.createElement({x: 17}); React.createElement({}); React.createElement(React.createElement('div')); - }).toWarnDev([ - 'Warning: React.createElement: type is invalid -- expected a string ' + - '(for built-in components) or a class/function (for composite ' + - 'components) but got: undefined. You likely forgot to export your ' + - "component from the file it's defined in, or you might have mixed up " + - 'default and named imports.', - 'Warning: React.createElement: type is invalid -- expected a string ' + - '(for built-in components) or a class/function (for composite ' + - 'components) but got: null.', - 'Warning: React.createElement: type is invalid -- expected a string ' + - '(for built-in components) or a class/function (for composite ' + - 'components) but got: boolean.', - 'Warning: React.createElement: type is invalid -- expected a string ' + - '(for built-in components) or a class/function (for composite ' + - 'components) but got: object.', - 'Warning: React.createElement: type is invalid -- expected a string ' + - '(for built-in components) or a class/function (for composite ' + - 'components) but got: object. You likely forgot to export your ' + - "component from the file it's defined in, or you might have mixed up " + - 'default and named imports.', - 'Warning: React.createElement: type is invalid -- expected a string ' + - '(for built-in components) or a class/function (for composite ' + - 'components) but got: element. Did you accidentally export JSX ' + - 'instead of a component?', - ]); + React.createElement({ $$typeof: {} }); + }).toWarnDev( + [ + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: undefined. You likely forgot to export your ' + + "component from the file it's defined in, or you might have mixed up " + + 'default and named imports.', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: null.', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: boolean.', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: object.', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: object. You likely forgot to export your ' + + "component from the file it's defined in, or you might have mixed up " + + 'default and named imports.', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: React element. Did you accidentally export JSX ' + + 'instead of a component?', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: object.', + ], + {withoutStack: true}, + ); // Should not log any additional warnings React.createElement('div'); From 537925f87d83550758cf63b6204acaea7650a85e Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Wed, 18 Jul 2018 00:13:37 -0400 Subject: [PATCH 7/9] runs prettier --- packages/events/EventPluginUtils.js | 8 ++------ packages/events/ResponderEventPlugin.js | 8 ++------ packages/react-dom/src/events/SyntheticWheelEvent.js | 8 ++------ packages/react-dom/src/events/TapEventPlugin.js | 4 +--- packages/react-test-renderer/src/ReactShallowRenderer.js | 4 +--- .../src/__tests__/ReactElementValidator-test.internal.js | 2 +- packages/shared/describeComponentFrame.js | 4 +--- scripts/bench/stats.js | 2 +- 8 files changed, 11 insertions(+), 29 deletions(-) diff --git a/packages/events/EventPluginUtils.js b/packages/events/EventPluginUtils.js index 6e7397d69f2b4..2bbe2b36d9bba 100644 --- a/packages/events/EventPluginUtils.js +++ b/packages/events/EventPluginUtils.js @@ -39,16 +39,12 @@ if (__DEV__) { const listenersIsArr = Array.isArray(dispatchListeners); const listenersLen = listenersIsArr ? dispatchListeners.length - : dispatchListeners - ? 1 - : 0; + : dispatchListeners ? 1 : 0; const instancesIsArr = Array.isArray(dispatchInstances); const instancesLen = instancesIsArr ? dispatchInstances.length - : dispatchInstances - ? 1 - : 0; + : dispatchInstances ? 1 : 0; warningWithoutStack( instancesIsArr === listenersIsArr && instancesLen === listenersLen, diff --git a/packages/events/ResponderEventPlugin.js b/packages/events/ResponderEventPlugin.js index f8acb05f5b70a..dc14523fff455 100644 --- a/packages/events/ResponderEventPlugin.js +++ b/packages/events/ResponderEventPlugin.js @@ -548,9 +548,7 @@ const ResponderEventPlugin = { ? eventTypes.responderStart : isResponderTouchMove ? eventTypes.responderMove - : isResponderTouchEnd - ? eventTypes.responderEnd - : null; + : isResponderTouchEnd ? eventTypes.responderEnd : null; if (incrementalTouch) { const gesture = ResponderSyntheticEvent.getPooled( @@ -573,9 +571,7 @@ const ResponderEventPlugin = { noResponderTouches(nativeEvent); const finalTouch = isResponderTerminate ? eventTypes.responderTerminate - : isResponderRelease - ? eventTypes.responderRelease - : null; + : isResponderRelease ? eventTypes.responderRelease : null; if (finalTouch) { const finalEvent = ResponderSyntheticEvent.getPooled( finalTouch, diff --git a/packages/react-dom/src/events/SyntheticWheelEvent.js b/packages/react-dom/src/events/SyntheticWheelEvent.js index 16435febcc8d3..b4c49f430ab96 100644 --- a/packages/react-dom/src/events/SyntheticWheelEvent.js +++ b/packages/react-dom/src/events/SyntheticWheelEvent.js @@ -16,9 +16,7 @@ const SyntheticWheelEvent = SyntheticMouseEvent.extend({ return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive). - 'wheelDeltaX' in event - ? -event.wheelDeltaX - : 0; + 'wheelDeltaX' in event ? -event.wheelDeltaX : 0; }, deltaY(event) { return 'deltaY' in event @@ -27,9 +25,7 @@ const SyntheticWheelEvent = SyntheticMouseEvent.extend({ 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive). - 'wheelDelta' in event - ? -event.wheelDelta - : 0; + 'wheelDelta' in event ? -event.wheelDelta : 0; }, deltaZ: null, diff --git a/packages/react-dom/src/events/TapEventPlugin.js b/packages/react-dom/src/events/TapEventPlugin.js index e3b03456c37a1..61e51f77921c5 100644 --- a/packages/react-dom/src/events/TapEventPlugin.js +++ b/packages/react-dom/src/events/TapEventPlugin.js @@ -94,9 +94,7 @@ function extractSingleTouch(nativeEvent) { return !hasTouches && hasChangedTouches ? changedTouches[0] - : hasTouches - ? touches[0] - : nativeEvent; + : hasTouches ? touches[0] : nativeEvent; } function getAxisCoordOfEvent( diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index de873596e7066..dd1e8f750d7a3 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -66,9 +66,7 @@ class ReactShallowRenderer { 'components, but the provided element type was `%s`.', Array.isArray(element.type) ? 'array' - : element.type === null - ? 'null' - : typeof element.type, + : element.type === null ? 'null' : typeof element.type, ); if (this._rendering) { diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index 7eaac35fe4d34..4d2b4af14e987 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -236,7 +236,7 @@ describe('ReactElementValidator', () => { React.createElement({x: 17}); React.createElement({}); React.createElement(React.createElement('div')); - React.createElement({ $$typeof: {} }); + React.createElement({$$typeof: {}}); }).toWarnDev( [ 'Warning: React.createElement: type is invalid -- expected a string ' + diff --git a/packages/shared/describeComponentFrame.js b/packages/shared/describeComponentFrame.js index 5c619e6164e09..3494c31e23799 100644 --- a/packages/shared/describeComponentFrame.js +++ b/packages/shared/describeComponentFrame.js @@ -21,8 +21,6 @@ export default function( ':' + source.lineNumber + ')' - : ownerName - ? ' (created by ' + ownerName + ')' - : '') + : ownerName ? ' (created by ' + ownerName + ')' : '') ); } diff --git a/scripts/bench/stats.js b/scripts/bench/stats.js index 9fb5883d83243..d178be65ad267 100644 --- a/scripts/bench/stats.js +++ b/scripts/bench/stats.js @@ -33,7 +33,7 @@ function calculateMeanAndSdOfRatioFromDeltaMethod( ) { const mean = (meanTest - meanControl) / meanControl - - (Math.pow(semControl, 2) * meanTest) / Math.pow(meanControl, 3); + Math.pow(semControl, 2) * meanTest / Math.pow(meanControl, 3); const variance = Math.pow(semTest / meanControl, 2) + Math.pow(semControl * meanTest, 2) / Math.pow(meanControl, 4); From 55bf68ad6c87d6a6de4fd0c551633e1c9105d556 Mon Sep 17 00:00:00 2001 From: Dylan Cutler Date: Wed, 18 Jul 2018 01:25:19 -0400 Subject: [PATCH 8/9] remove unrelated changes --- packages/events/EventPluginUtils.js | 8 ++++++-- packages/events/ResponderEventPlugin.js | 8 ++++++-- packages/react-dom/src/events/SyntheticWheelEvent.js | 8 ++++++-- packages/react-dom/src/events/TapEventPlugin.js | 4 +++- packages/react-test-renderer/src/ReactShallowRenderer.js | 4 +++- packages/shared/describeComponentFrame.js | 4 +++- scripts/bench/stats.js | 2 +- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/packages/events/EventPluginUtils.js b/packages/events/EventPluginUtils.js index 2bbe2b36d9bba..6e7397d69f2b4 100644 --- a/packages/events/EventPluginUtils.js +++ b/packages/events/EventPluginUtils.js @@ -39,12 +39,16 @@ if (__DEV__) { const listenersIsArr = Array.isArray(dispatchListeners); const listenersLen = listenersIsArr ? dispatchListeners.length - : dispatchListeners ? 1 : 0; + : dispatchListeners + ? 1 + : 0; const instancesIsArr = Array.isArray(dispatchInstances); const instancesLen = instancesIsArr ? dispatchInstances.length - : dispatchInstances ? 1 : 0; + : dispatchInstances + ? 1 + : 0; warningWithoutStack( instancesIsArr === listenersIsArr && instancesLen === listenersLen, diff --git a/packages/events/ResponderEventPlugin.js b/packages/events/ResponderEventPlugin.js index dc14523fff455..f8acb05f5b70a 100644 --- a/packages/events/ResponderEventPlugin.js +++ b/packages/events/ResponderEventPlugin.js @@ -548,7 +548,9 @@ const ResponderEventPlugin = { ? eventTypes.responderStart : isResponderTouchMove ? eventTypes.responderMove - : isResponderTouchEnd ? eventTypes.responderEnd : null; + : isResponderTouchEnd + ? eventTypes.responderEnd + : null; if (incrementalTouch) { const gesture = ResponderSyntheticEvent.getPooled( @@ -571,7 +573,9 @@ const ResponderEventPlugin = { noResponderTouches(nativeEvent); const finalTouch = isResponderTerminate ? eventTypes.responderTerminate - : isResponderRelease ? eventTypes.responderRelease : null; + : isResponderRelease + ? eventTypes.responderRelease + : null; if (finalTouch) { const finalEvent = ResponderSyntheticEvent.getPooled( finalTouch, diff --git a/packages/react-dom/src/events/SyntheticWheelEvent.js b/packages/react-dom/src/events/SyntheticWheelEvent.js index b4c49f430ab96..16435febcc8d3 100644 --- a/packages/react-dom/src/events/SyntheticWheelEvent.js +++ b/packages/react-dom/src/events/SyntheticWheelEvent.js @@ -16,7 +16,9 @@ const SyntheticWheelEvent = SyntheticMouseEvent.extend({ return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive). - 'wheelDeltaX' in event ? -event.wheelDeltaX : 0; + 'wheelDeltaX' in event + ? -event.wheelDeltaX + : 0; }, deltaY(event) { return 'deltaY' in event @@ -25,7 +27,9 @@ const SyntheticWheelEvent = SyntheticMouseEvent.extend({ 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive). - 'wheelDelta' in event ? -event.wheelDelta : 0; + 'wheelDelta' in event + ? -event.wheelDelta + : 0; }, deltaZ: null, diff --git a/packages/react-dom/src/events/TapEventPlugin.js b/packages/react-dom/src/events/TapEventPlugin.js index 61e51f77921c5..e3b03456c37a1 100644 --- a/packages/react-dom/src/events/TapEventPlugin.js +++ b/packages/react-dom/src/events/TapEventPlugin.js @@ -94,7 +94,9 @@ function extractSingleTouch(nativeEvent) { return !hasTouches && hasChangedTouches ? changedTouches[0] - : hasTouches ? touches[0] : nativeEvent; + : hasTouches + ? touches[0] + : nativeEvent; } function getAxisCoordOfEvent( diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index dd1e8f750d7a3..de873596e7066 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -66,7 +66,9 @@ class ReactShallowRenderer { 'components, but the provided element type was `%s`.', Array.isArray(element.type) ? 'array' - : element.type === null ? 'null' : typeof element.type, + : element.type === null + ? 'null' + : typeof element.type, ); if (this._rendering) { diff --git a/packages/shared/describeComponentFrame.js b/packages/shared/describeComponentFrame.js index 3494c31e23799..5c619e6164e09 100644 --- a/packages/shared/describeComponentFrame.js +++ b/packages/shared/describeComponentFrame.js @@ -21,6 +21,8 @@ export default function( ':' + source.lineNumber + ')' - : ownerName ? ' (created by ' + ownerName + ')' : '') + : ownerName + ? ' (created by ' + ownerName + ')' + : '') ); } diff --git a/scripts/bench/stats.js b/scripts/bench/stats.js index d178be65ad267..9fb5883d83243 100644 --- a/scripts/bench/stats.js +++ b/scripts/bench/stats.js @@ -33,7 +33,7 @@ function calculateMeanAndSdOfRatioFromDeltaMethod( ) { const mean = (meanTest - meanControl) / meanControl - - Math.pow(semControl, 2) * meanTest / Math.pow(meanControl, 3); + (Math.pow(semControl, 2) * meanTest) / Math.pow(meanControl, 3); const variance = Math.pow(semTest / meanControl, 2) + Math.pow(semControl * meanTest, 2) / Math.pow(meanControl, 4); From 095832e03e5e808fd90eca3dcf49b931443e6ea7 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 1 Aug 2018 18:40:06 +0100 Subject: [PATCH 9/9] Tweak the message --- packages/react/src/ReactElementValidator.js | 8 ++++---- .../ReactElementValidator-test.internal.js | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/react/src/ReactElementValidator.js b/packages/react/src/ReactElementValidator.js index dcebe27ba302a..ba4f87f66fe9e 100644 --- a/packages/react/src/ReactElementValidator.js +++ b/packages/react/src/ReactElementValidator.js @@ -287,12 +287,12 @@ export function createElementWithValidation(type, props, children) { typeString = 'null'; } else if (Array.isArray(type)) { typeString = 'array'; + } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) { + typeString = `<${getComponentName(type.type) || 'Unknown'} />`; + info = + ' Did you accidentally export a JSX literal instead of a component?'; } else { typeString = typeof type; - if (type && type.$$typeof === REACT_ELEMENT_TYPE) { - typeString = 'React element'; - info = ' Did you accidentally export JSX instead of a component?'; - } } warning( diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index 4d2b4af14e987..6f881825f845b 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -229,6 +229,7 @@ describe('ReactElementValidator', () => { }); it('gives a helpful error when passing invalid types', () => { + function Foo() {} expect(() => { React.createElement(undefined); React.createElement(null); @@ -236,7 +237,9 @@ describe('ReactElementValidator', () => { React.createElement({x: 17}); React.createElement({}); React.createElement(React.createElement('div')); - React.createElement({$$typeof: {}}); + React.createElement(React.createElement(Foo)); + React.createElement(React.createElement(React.createContext().Consumer)); + React.createElement({$$typeof: 'non-react-thing'}); }).toWarnDev( [ 'Warning: React.createElement: type is invalid -- expected a string ' + @@ -260,8 +263,16 @@ describe('ReactElementValidator', () => { 'default and named imports.', 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + - 'components) but got: React element. Did you accidentally export JSX ' + + 'components) but got:
. Did you accidentally export a JSX literal ' + 'instead of a component?', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: . Did you accidentally export a JSX literal ' + + 'instead of a component?', + 'Warning: React.createElement: type is invalid -- expected a string ' + + '(for built-in components) or a class/function (for composite ' + + 'components) but got: . Did you accidentally ' + + 'export a JSX literal instead of a component?', 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + 'components) but got: object.',