You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding some context to this - setting the crop onImageLoad didn't work for me.
The crop dimensions will be correctly set, but the mask itself will be broken.
If you inspect the DOM when this happens, it seems like the of the mask SVG has 0x0 dimensions.
I was able to force refresh it on load by doing document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")
I'm curious if there is a better way around this. I am unable to consistently reproduce this issue.
Adding some context to this - setting the crop onImageLoad didn't work for me. The crop dimensions will be correctly set, but the mask itself will be broken.
If you inspect the DOM when this happens, it seems like the of the mask SVG has 0x0 dimensions. I was able to force refresh it on load by doing document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")
I'm curious if there is a better way around this. I am unable to consistently reproduce this issue.
Is this in a modal as well? Does your modal have some opening animation that changes the height?
Remove default crop value const [crop, setCrop] = useState();
I ended up using option 2. FYI, if you need to specify a crop do it on imageLoad with setCrop({ ... }) That's how I'm doing it and I fixed the issue I was having. \o/
Activity
Djibdjib commentedon Feb 6, 2024
Ok i found the solution, i use the onLoad attribute on the image to set the crop values. It works !
immanu10 commentedon Feb 6, 2024
@Djibdjib I'm facing the same issue even though I'm using the onLoad attribute. Do you mind sharing what exactly you did to fix it?
Djibdjib commentedon Feb 6, 2024
@immanu10 Yeah of course !
yuhao-wong commentedon Feb 14, 2024
Adding some context to this - setting the crop onImageLoad didn't work for me.
The crop dimensions will be correctly set, but the mask itself will be broken.
If you inspect the DOM when this happens, it seems like the of the mask SVG has 0x0 dimensions.
I was able to force refresh it on load by doing
document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")I'm curious if there is a better way around this. I am unable to consistently reproduce this issue.

dominictobias commentedon Feb 15, 2024
Is this in a modal as well? Does your modal have some opening animation that changes the height?
yuhao-wong commentedon Feb 15, 2024
Yes its in a modal, but I am rendering it with React.createPortal.
No animation.
hanurii commentedon Aug 30, 2024
In my case, the issue was resolved when I didn't provide initial values in the crop's useState.
ak-pdeshaies commentedon Sep 4, 2024
THANK YOU!!!
Both proposed solution found here worked for me
document.querySelector(".ReactCrop__crop-mask")?.setAttribute("height", "100%")const [crop, setCrop] = useState();I ended up using option 2. FYI, if you need to specify a crop do it on imageLoad with setCrop({ ... }) That's how I'm doing it and I fixed the issue I was having. \o/