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
[Slot] Access ref from props else fallback to element.ref #2811
base: main
Are you sure you want to change the base?
Conversation
Just chiming in to say that I had an issue with Portal when used in conjunction with |
Thanks for fixing this |
Thank you! |
Is there a way to fix this manually / locally until the official fix is out? The 7x 'element.ref' warnings I am getting on each page refresh are very annoying. |
@juliusmarminge I applied the same fix to |
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.
LGTM
Just a gentle reminder that this PR being merged and released is so valuable for a lot of people. Thank you. |
const ref = useComposedRefs(presence.ref, (child as any).ref); | ||
// Accessing the ref from props, else fallback to element.ref | ||
// https://github.com/facebook/react/pull/28348 | ||
const childrenRef = child.props.ref ?? (child as any).ref; |
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.
It's fine to access child.ref
conditionally. React only warns when accessing child.ref
iff a ref
prop is actually passed.
Description
fix #2769
Starting from the React 18.3.0 canary, accessing the ref via
element.ref
will throw a warning, andelement.ref
will be removed in the future React release.Instead, we should access the ref from props. To maintain the backward compatibility, we can do
children.props.ref ?? children.ref
.