-
Notifications
You must be signed in to change notification settings - Fork 440
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
fix: support field presence avatars on react 19 #7308
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Aug 2, 2024 4:00 PM (UTC)
|
ricokahler
approved these changes
Aug 5, 2024
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.
the logic checks out for me. nice find!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In React 19 it's possible to set a
ref
as a prop, while in React 18 you must implementReact.forwardRef
for this.Components that implement
React.forwardRef
isn't impacted by this change, and won't see thatref
exists as a prop. But for components likeWithIntersection
, it's now important to have the right order when setting refs and spreading props:On React 18 this is fine, because
<Component ref={123} />
won't result inprops
containingref={123}
.On React 19 it's not, because not only is
<Component ref={123} />
now possible and will result inprops.ref=123
, it also means that if aref
prop isn't defined, it'll benull
.In other words, on React 18 the resulting render is roughly:
<div {...props} ref={ref} />
, but on React 19 it's:<div ref={ref} {...({ ...props, ref: props.ref ?? null })} />
.The best way to mitigate this is to ensure that props are spread first, that way it's not possible to accidentally overriden:
This behaviour can be verified with the React DevTools on the deployments:
React 18 (Hook 1 is set)
React 19 (Hook 1 is
Note that the hook remains `null`, and that there's now a `ref` prop with `null`, which is causing it.null
)React 19 (with the fix applied)
What to review
Does it make sense?
Testing
Test on https://test-studio.sanity.dev/ for a working reference, use https://test-next-studio.sanity.dev/ to reproduce the bug, and finally https://test-next-studio-git-fix-field-presence-on-react-19.sanity.dev/ demonstrates the fix.
Notes for release
Fixes an issue causing the Presence Avatar Overlays on form fields not to appear when the Studio is embedded in a React 19 app.