react-image-crop icon indicating copy to clipboard operation
react-image-crop copied to clipboard

Crop width randomly becomes 0

Open knarah opened this issue 3 years ago • 1 comments

Hello

My issue is that, once out of 50 tries or once out of 100 tries, the crop area doesn't appear. And when I console logged the crop, after onChange the crop width set to 0, and I could't figure out why.


const [crop, setCrop] = React.useState({
    unit: '%',
    width: 100,
    aspect,
  }); // initial crop
...

return (
 <ReactCrop
      src={file}
      crop={crop}
      onImageLoaded={(image) => {
        console.log('crop3', crop);

        imageRef.current = image;
      }}

      onChange={(percentCrop) =>
        {
          console.log('crop1', crop);
          console.log('copr4', percentCrop) // I think from here the crop width becomes 0
          setCrop(percentCrop);
        }
      }

      onComplete={(crop) => {
        console.log('crop2', crop);
        makeClientCrop(crop);
      }}
)

Screenshot from 2022-10-31 22-04-38

Like I mentioned earlier, this bug happens very rarely and ramdomly but I still need to fix it. Could you please hele me? Thank you

knarah avatar Nov 02 '22 12:11 knarah

Hi, sorry but I'm no longer support < v10 anymore, my guess is that there is a bug in the code which detects if the aspect crop is invalid and tries to fix it - this code had various bugs and I stopped trying to "complete" or fix aspect crops.

You can read about how to upgrade to v10 here: https://github.com/DominicTobias/react-image-crop/releases/tag/10.0.0-beta.0 And check the CodeSandbox demo for an example

dominictobias avatar Nov 02 '22 13:11 dominictobias