Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude forwardRef and memo from stack frames #18559

Merged
merged 1 commit into from Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/react-reconciler/src/ReactFiberComponentStack.js
Expand Up @@ -17,7 +17,6 @@ import {
FunctionComponent,
IndeterminateComponent,
ForwardRef,
MemoComponent,
SimpleMemoComponent,
Block,
ClassComponent,
Expand Down Expand Up @@ -50,8 +49,6 @@ function describeFiber(fiber: Fiber): string {
return describeFunctionComponentFrame(fiber.type, source, owner);
case ForwardRef:
return describeFunctionComponentFrame(fiber.type.render, source, owner);
case MemoComponent:
return describeFunctionComponentFrame(fiber.type.type, source, owner);
case Block:
return describeFunctionComponentFrame(fiber.type._render, source, owner);
case ClassComponent:
Expand Down
16 changes: 13 additions & 3 deletions packages/react-reconciler/src/__tests__/ReactMemo-test.js
Expand Up @@ -392,12 +392,20 @@ describe('memo', () => {
Outer.defaultProps = {outer: 0};

// No warning expected because defaultProps satisfy both.
ReactNoop.render(<Outer />);
ReactNoop.render(
<div>
<Outer />
</div>,
);
expect(Scheduler).toFlushWithoutYielding();

// Mount
expect(() => {
ReactNoop.render(<Outer inner="2" middle="3" outer="4" />);
ReactNoop.render(
<div>
<Outer inner="2" middle="3" outer="4" />
</div>,
);
expect(Scheduler).toFlushWithoutYielding();
}).toErrorDev([
'Invalid prop `outer` of type `string` supplied to `Inner`, expected `number`.',
Expand All @@ -408,7 +416,9 @@ describe('memo', () => {
// Update
expect(() => {
ReactNoop.render(
<Outer inner={false} middle={false} outer={false} />,
<div>
<Outer inner={false} middle={false} outer={false} />
</div>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning no longer includes any stack because there's only a Memo. This triggers our internal warning about not expecting a stack on the warning. However, that's not realistic so let's test it with a stack.

);
expect(Scheduler).toFlushWithoutYielding();
}).toErrorDev([
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/ReactComponentStackFrame.js
Expand Up @@ -121,14 +121,16 @@ export function describeUnknownElementTypeFrameInDEV(
case REACT_FORWARD_REF_TYPE:
return describeFunctionComponentFrame(type.render, source, ownerFn);
case REACT_MEMO_TYPE:
return describeFunctionComponentFrame(type.type, source, ownerFn);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also a bug because the inner one might not be a function.

// Memo may contain any component type so we recursively resolve it.
return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
gaearon marked this conversation as resolved.
Show resolved Hide resolved
case REACT_BLOCK_TYPE:
return describeFunctionComponentFrame(type._render, source, ownerFn);
case REACT_LAZY_TYPE: {
const lazyComponent: LazyComponent<any, any> = (type: any);
const payload = lazyComponent._payload;
const init = lazyComponent._init;
try {
// Lazy may contain any component type so we recursively resolve it.
return describeUnknownElementTypeFrameInDEV(
init(payload),
source,
Expand Down