-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fix unrecognised forwardedRef prop
#8570
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
Conversation
nerrad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better to remove the forwardedRef prop on any leaf components rather than in the HOC.
| return <WrappedComponent { ...this.props } ref={ this.handleRef } />; | ||
| return ( | ||
| <WrappedComponent | ||
| { ...omit( this.props, [ 'forwardedRef' ] ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance-wise, we could probably benefit by just passing the original props as a standalone prop value from within forwardRef, rather than iterating the props object to remove forwardedRef on every render.
return forwardRef( ( props, ref ) => {
return <Wrapper ownProps={ props } forwardedRef={ ref } />;
} );For example, we do this with withSelect:
| ownProps={ ownProps } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion! I've updated the PR.
How would this be implemented? |
Your suggestion here: #8570 (review) would make my suggestion moot :). |
9078205 to
d9b7032
Compare
Have `withGlobalEvents` omit the `forwardedRef` prop. This prevents the prop being added to HTML in some cases, e.g. when used in `FocusableIframe`.
d9b7032 to
13dcbda
Compare
aduth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Fixes a warning I noticed while testing #8556.
withGlobalEventswas settingforwardedRefon the wrapped component, which caused anUnrecognised forwardedRef propReact warning inFocusableIframe.Also corrects some incorrect indentation in some embedded JavaScript.
How has this been tested?
Custom HTMLblockPreviewbuttonNo errors or warnings should appear in the console.