-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
MediaReplaceFlow: Avoid React warning when selecting media #34618
Conversation
Size Change: +2.34 kB (0%) Total Size: 1.05 MB
ℹ️ View Unchanged
|
setMediaURLValue( media.url ); | ||
onSelect( media ); |
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.
Could you leave an inline comment? In what case does it unmount the component?
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 that depends on the parent component and what it does inside the onSelect
callback.
The "Post Featured Image" edit component will re-render it when new media data is fetched:
gutenberg/packages/block-library/src/post-featured-image/edit.js
Lines 122 to 133 in 7791d58
{ !! media && ! isDescendentOfQueryLoop && ( | |
<BlockControls group="other"> | |
<MediaReplaceFlow | |
mediaId={ featuredImage } | |
mediaURL={ media.source_url } | |
allowedTypes={ ALLOWED_MEDIA_TYPES } | |
accept="image/*" | |
onSelect={ onSelectImage } | |
onError={ onUploadError } | |
/> | |
</BlockControls> | |
) } |
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.
@ellatrix, the cause of the unmounting can be different in each case, and I don't think the inline comment would be enough to provide the necessary information.
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.
Surely there could be a comment explaining why this order is needed? This change is just really easy to revert without getting an error for the automated tests, so it seems like a good place to comment. Also, why are we not getting an error in the automated tests? :)
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.
Let's check with #34730.
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.
Added inline comment in 55806ce.
Would you please let me know if you think that wording needs changing?
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.
Hi, @ellatrix
I just wanted to check if it's okay to merge this fix after adding the inline comment.
Thanks
Description
The component was calling
setMediaURLValue
after calling theonSelect
callback, which in some cases can unmount the component.Initially reported in #34506
How has this been tested?
DevTools console shouldn't display a "Can't perform a React state update on an unmounted component" warning.
Types of changes
Bugfix
Checklist:
*.native.js
files for terms that need renaming or removal).