@samitouri / QOS-React / commits / 204d3dd703

Throw if undefined is returned from a composite component

Andrew Clark committed Jan 11, 2017 at 17:51 UTC 204d3dd703f2ef21953e1509302456f3800a07db
1 file changed +21
src/renderers/shared/fiber/ReactChildFiber.js
+21
@@ -61,8 +61,10 @@ const {
61 const isArray = Array.isArray;
62
63 const {
64 + FunctionalComponent,
65 ClassComponent,
66 HostText,
67 + HostRoot,
68 HostPortal,
69 CoroutineComponent,
70 YieldComponent,
@@ -1197,6 +1199,25 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1199 }
1200 }
1201
1202 + if (typeof newChild === 'undefined') {
1203 + switch (returnFiber.tag) {
1204 + case HostRoot:
1205 + // TODO: Top-level render
1206 + break;
1207 + case ClassComponent:
1208 + case FunctionalComponent: {
1209 + const Component = returnFiber.type;
1210 + invariant(
1211 + false,
1212 + '%s: Nothing was returned from render. This usually means a ' +
1213 + 'return statement is missing. Or, to render nothing, ' +
1214 + 'return null.',
1215 + Component.displayName || Component.name || 'Component'
1216 + );
1217 + }
1218 + }
1219 + }
1220 +
1221 // Remaining cases are all treated as empty.
1222 return deleteRemainingChildren(returnFiber, currentFirstChild);
1223 }