-
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
Image: Manually update resizable box state when we don't have dimenssions #29919
Image: Manually update resizable box state when we don't have dimenssions #29919
Conversation
useEffect( () => { | ||
if ( url && resizableBoxRef.current && ! width && ! height ) { | ||
resizableBoxRef.current.updateSize( { | ||
width: 'auto', | ||
height: 'auto', | ||
} ); | ||
} | ||
}, [ url, width, height ] ); |
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.
Why is this being called in a useEffect
instead of in updateImage
where the attributes are reset?
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.
Or better yet, could we just set the width
and height
of the ResizableBox
component to be 'auto'
when attributes.width
and attributes.height
are undefined
?
<ResizableBox
size={ {
width: width ?? 'auto',
height: height ?? 'auto',
} }
...
/>
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, @ajlende
Thanks for the review.
Why is this being called in a useEffect instead of in updateImage where the attributes are reset?
The attributes are reset in onSelectImage
and updateImage
. Using the useEffect
seemed more optimal at the time.
Or better yet, could we just set the width and height of the ResizableBox component to be 'auto' when attributes.width and attributes.height are undefined?
Thanks for suggesting a clearer approach 🙇 This is the reason I love reviews.
…eight When changing to a different image, we reset dimension attributes, including size props for the resizable box. But this doesn't automatically reset dimensions in the resizable box state, which is used for inline styles. So we have to do it manually. See WordPress#23985.
4f7be48
to
de97b1a
Compare
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.
Looks good to me!
Description
When changing to a different image, we reset dimension attributes, including size props for the resizable box. But this doesn't automatically reset dimensions in the resizable box state, which is used for inline styles. So we have to do it manually.
Fixes #23985.
P.S. This might be an issue with the upstream package -
re-resizable
.How has this been tested?
Types of changes
Bugfix
Checklist: