Skip to content

Commit

Permalink
Use both displayName and name in forwardRef/memo (#29625)
Browse files Browse the repository at this point in the history
When defining a displayName on forwardRef/memo we forward that name to
the inner function.

We used to use displayName for this but in #29206 I switched this to use
`"name"`. That's because V8 doesn't use displayName, it only uses the
overridden name in stack traces. This is the only thing covered by our
tests for component stacks.

However, I realized that Safari only uses displayName and not the name.
So this sets both.
  • Loading branch information
sebmarkbage committed May 31, 2024
1 parent 8fd963a commit 63d673c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react/src/ReactForwardRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function forwardRef<Props, ElementType: React$ElementType>(
Object.defineProperty(render, 'name', {
value: name,
});
render.displayName = name;
}
},
});
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/ReactMemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function memo<Props>(
Object.defineProperty(type, 'name', {
value: name,
});
type.displayName = name;
}
},
});
Expand Down

0 comments on commit 63d673c

Please sign in to comment.