Skip to content

Commit 18fde8e

Browse files
authored
Revert "Warn about undefined return value for memo and forwardRef (#19550)"
This reverts commit a63893f.
1 parent 2704bb5 commit 18fde8e

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

packages/react-dom/src/__tests__/ReactEmptyComponent-test.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -316,24 +316,4 @@ describe('ReactEmptyComponent', () => {
316316
const noscript2 = container.firstChild;
317317
expect(noscript2).toBe(null);
318318
});
319-
320-
it('should warn about React.forwardRef that returns undefined', () => {
321-
const Empty = () => {};
322-
const EmptyForwardRef = React.forwardRef(Empty);
323-
324-
expect(() => {
325-
ReactTestUtils.renderIntoDocument(<EmptyForwardRef />);
326-
}).toThrowError(
327-
'ForwardRef(Empty)(...): Nothing was returned from render.',
328-
);
329-
});
330-
331-
it('should warn about React.memo that returns undefined', () => {
332-
const Empty = () => {};
333-
const EmptyMemo = React.memo(Empty);
334-
335-
expect(() => {
336-
ReactTestUtils.renderIntoDocument(<EmptyMemo />);
337-
}).toThrowError('Empty(...): Nothing was returned from render.');
338-
});
339319
});

packages/react-reconciler/src/ReactChildFiber.new.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import {
2929
ClassComponent,
3030
HostText,
3131
HostPortal,
32-
ForwardRef,
3332
Fragment,
34-
SimpleMemoComponent,
3533
Block,
3634
} from './ReactWorkTags';
3735
import invariant from 'shared/invariant';
@@ -1395,16 +1393,14 @@ function ChildReconciler(shouldTrackSideEffects) {
13951393
// Intentionally fall through to the next case, which handles both
13961394
// functions and classes
13971395
// eslint-disable-next-lined no-fallthrough
1398-
case Block:
1399-
case FunctionComponent:
1400-
case ForwardRef:
1401-
case SimpleMemoComponent: {
1396+
case FunctionComponent: {
1397+
const Component = returnFiber.type;
14021398
invariant(
14031399
false,
14041400
'%s(...): Nothing was returned from render. This usually means a ' +
14051401
'return statement is missing. Or, to render nothing, ' +
14061402
'return null.',
1407-
getComponentName(returnFiber.type) || 'Component',
1403+
Component.displayName || Component.name || 'Component',
14081404
);
14091405
}
14101406
}

packages/react-reconciler/src/ReactChildFiber.old.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import {
2929
ClassComponent,
3030
HostText,
3131
HostPortal,
32-
ForwardRef,
3332
Fragment,
34-
SimpleMemoComponent,
3533
Block,
3634
} from './ReactWorkTags';
3735
import invariant from 'shared/invariant';
@@ -1387,16 +1385,14 @@ function ChildReconciler(shouldTrackSideEffects) {
13871385
// Intentionally fall through to the next case, which handles both
13881386
// functions and classes
13891387
// eslint-disable-next-lined no-fallthrough
1390-
case Block:
1391-
case FunctionComponent:
1392-
case ForwardRef:
1393-
case SimpleMemoComponent: {
1388+
case FunctionComponent: {
1389+
const Component = returnFiber.type;
13941390
invariant(
13951391
false,
13961392
'%s(...): Nothing was returned from render. This usually means a ' +
13971393
'return statement is missing. Or, to render nothing, ' +
13981394
'return null.',
1399-
getComponentName(returnFiber.type) || 'Component',
1395+
Component.displayName || Component.name || 'Component',
14001396
);
14011397
}
14021398
}

0 commit comments

Comments
 (0)