GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Warn about undefined return value for memo and forwardRef (#19550) · react/react@a63893f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • react-dom/src/__tests__
      • ReactEmptyComponent-test.js
    • react-reconciler/src
      • ReactChildFiber.new.js
      • ReactChildFiber.old.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactEmptyComponent-test.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,24 @@ 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+
});
319339
});
Collapse file

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

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactChildFiber.new.js
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
ClassComponent,
3030
HostText,
3131
HostPortal,
32+
ForwardRef,
3233
Fragment,
34+
SimpleMemoComponent,
3335
Block,
3436
} from './ReactWorkTags';
3537
import invariant from 'shared/invariant';
@@ -1393,14 +1395,16 @@ function ChildReconciler(shouldTrackSideEffects) {
13931395
// Intentionally fall through to the next case, which handles both
13941396
// functions and classes
13951397
// eslint-disable-next-lined no-fallthrough
1396-
case FunctionComponent: {
1397-
const Component = returnFiber.type;
1398+
case Block:
1399+
case FunctionComponent:
1400+
case ForwardRef:
1401+
case SimpleMemoComponent: {
13981402
invariant(
13991403
false,
14001404
'%s(...): Nothing was returned from render. This usually means a ' +
14011405
'return statement is missing. Or, to render nothing, ' +
14021406
'return null.',
1403-
Component.displayName || Component.name || 'Component',
1407+
getComponentName(returnFiber.type) || 'Component',
14041408
);
14051409
}
14061410
}
Collapse file

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

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactChildFiber.old.js
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import {
2929
ClassComponent,
3030
HostText,
3131
HostPortal,
32+
ForwardRef,
3233
Fragment,
34+
SimpleMemoComponent,
3335
Block,
3436
} from './ReactWorkTags';
3537
import invariant from 'shared/invariant';
@@ -1385,14 +1387,16 @@ function ChildReconciler(shouldTrackSideEffects) {
13851387
// Intentionally fall through to the next case, which handles both
13861388
// functions and classes
13871389
// eslint-disable-next-lined no-fallthrough
1388-
case FunctionComponent: {
1389-
const Component = returnFiber.type;
1390+
case Block:
1391+
case FunctionComponent:
1392+
case ForwardRef:
1393+
case SimpleMemoComponent: {
13901394
invariant(
13911395
false,
13921396
'%s(...): Nothing was returned from render. This usually means a ' +
13931397
'return statement is missing. Or, to render nothing, ' +
13941398
'return null.',
1395-
Component.displayName || Component.name || 'Component',
1399+
getComponentName(returnFiber.type) || 'Component',
13961400
);
13971401
}
13981402
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.