Skip to content
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

Examples and local implementation crash on ios browser #541

Open
erodriguezvesti opened this issue May 29, 2024 · 21 comments
Open

Examples and local implementation crash on ios browser #541

erodriguezvesti opened this issue May 29, 2024 · 21 comments
Labels
bug Something isn't working

Comments

@erodriguezvesti
Copy link

that's all, simply open examples on ios mobile browser and page crashes. i try with locally implementation and got the same issue

@ValentinH
Copy link
Owner

I finally managed to get access to an iOS device. I tested the website (https://valentinh.github.io/react-easy-crop/) and it works fine. What examples are you referring to?

@erodriguezvesti
Copy link
Author

erodriguezvesti commented Jun 21, 2024

RPReplay_Final1718948373.MP4

Hi! This happens with iOS. In my implementation in my project, the same thing happens. In my project, it doesn't crash automatically, but when cropping, it collapses and throws the same error

Video if from this url -> https://codesandbox.io/s/v69ly910ql

@ValentinH
Copy link
Owner

ValentinH commented Jun 21, 2024 via email

@erodriguezvesti
Copy link
Author

That's the problem. I tried to fix it or figure out the issue, but the console doesn't show any errors or logs. The browser just says "an error occurred" many times and crashes the page.

@ValentinH
Copy link
Owner

What about the crash on your app, not on codesandbox?

@erodriguezvesti
Copy link
Author

Here is real time console when web site crashes

Screen.Recording.2024-06-21.at.02.49.33.mov

You cannot see error messages about react easy crop

@erodriguezvesti
Copy link
Author

https://codesandbox.io/p/sandbox/react-easy-crop-v69ly910ql fails on startup , i don't know why https://codesandbox.io/s/v69ly910ql not crashes

@ValentinH
Copy link
Owner

It seems that the app crashes when the crop button is clicked. It means that the issue isn't happening in the lib code but in the cropping function.

@erodriguezvesti
Copy link
Author

In my implementation? No only drag crop and crash, in code sanbox crop is loaded and crash

@erodriguezvesti
Copy link
Author

can you test https://codesandbox.io/p/sandbox/react-easy-crop-v69ly910ql on ios device?

@erodriguezvesti
Copy link
Author

update: Testing previous versions, version 5.0.2 works well and the browser does not crash

@ValentinH
Copy link
Owner

Thanks for catching that. Then it means that 5.0.4 brought the issue. Are you using the objectFit property?

@erodriguezvesti
Copy link
Author

erodriguezvesti commented Jun 22, 2024

since 5.0.3 crash on ios device.

No, i'm not using objectFit, my code is really simple

import { useModal } from "@/context/modal/modal.provider";
import { Button } from "@nextui-org/react";
import { useCallback, useRef, useState } from "react";
import Cropper from "react-easy-crop";
import getCroppedImg from "./get-cropped-img";

interface ICropImageProps {
  b64: string;
  onConfirm: (b64: string) => void;
  onClose?: () => void;
  cropRatio?: number;
}

const CropImage = ({
  b64,
  onConfirm,
  onClose = () => {},
  cropRatio = 1 / 1,
}: ICropImageProps) => {
  const { closeModal } = useModal();
  const [crop, setCrop] = useState({ x: 0, y: 0 });
  const croppedAreaPixelsRef = useRef<any>(null);

  const onCropComplete = useCallback((croppedArea, croppedAreaPixels) => {
    croppedAreaPixelsRef.current = croppedAreaPixels;
  }, []);

  const showCroppedImage = useCallback(async () => {
    try {
      const croppedImage = await getCroppedImg(
        b64,
        croppedAreaPixelsRef.current,
        0
      );
      onConfirm(croppedImage as string);
      closeModal();
    } catch (e) {
      console.error(e);
    }
  }, [b64, onConfirm, closeModal]);

  const onCloseCrop = useCallback(() => {
    closeModal();
    onClose();
  }, [closeModal, onClose]);

  return (
    <div className="p-6">
      <div style={{ minHeight: 350, height: 350 }} className="relative">
        <Cropper
          image={b64}
          crop={crop}
          aspect={cropRatio}
          onCropChange={setCrop}
          onCropComplete={onCropComplete}
        />
      </div>

      <div className="flex justify-between mt-6">
        <Button onClick={onCloseCrop} color="danger" variant="bordered">
          Cancelar
        </Button>
        <Button onClick={showCroppedImage} color="success">
          Confirmar
        </Button>
      </div>
    </div>
  );
};

export default CropImage;

@ValentinH
Copy link
Owner

ValentinH commented Jun 22, 2024

So it doesn't crash on 5.0.2? What I don't get is that 5.0.3 only added changes to the README 🤔

@ValentinH
Copy link
Owner

I confirm that, at the first look, nothing looks suspicious in your code. I'll try to reproduce when I'm back on my computer.

@erodriguezvesti
Copy link
Author

Sorry, I've been testing different versions for a while and the same thing happens with all of them. Sometimes it occurs less frequently, but you can still experience the same problem. The console doesn't show any error; everything just restarts. 😔😔😔

What seems most strange to me and could provide a clue is that in this URL https://codesandbox.io/p/sandbox/react-easy-crop-v69ly910ql the problem occurs, but in this one https://codesandbox.io/s/v69ly910ql it does not.

@ValentinH ValentinH added the bug Something isn't working label Jun 22, 2024
@ValentinH
Copy link
Owner

What version of iOS are you testing on?
I'm testing on iOS 17.5 and didn't managed to reproduce with the sandbox you shared 🤔

image

Do you manage to reproduce on the preview url: https://v69ly910ql.csb.app?

@ValentinH
Copy link
Owner

What seems most strange to me and could provide a clue is that in this URL codesandbox.io/p/sandbox/react-easy-crop-v69ly910ql the problem occurs, but in this one codesandbox.io/s/v69ly910ql it does not.

These are 2 different versions of the codesandbox editor. Therefore, I would say that the issue is more on the codesandbox side than on the lib itself.

Are you able to create a small repository of your example that still reproduces the error and share it here please? The goal is to remove codesandbox from the equation.

@erodriguezvesti
Copy link
Author

After a thousand tests, the error occurs when having a tracking provider like Clarity or Hotjar; when initializing the crop or moving the image, the site crashes. I imagine it must be issues with these services. For now, I solved it by disabling Clarity on my website. Many thanks for your help and follow-up.

@erodriguezvesti
Copy link
Author

What version of iOS are you testing on? I'm testing on iOS 17.5 and didn't managed to reproduce with the sandbox you shared 🤔

image

Do you manage to reproduce on the preview url: https://v69ly910ql.csb.app?

That's a point, the error only occurs on real devices. I couldn't reproduce it on the emulator either, but I did on four real devices.

@ValentinH
Copy link
Owner

After a thousand tests, the error occurs when having a tracking provider like Clarity or Hotjar; when initializing the crop or moving the image, the site crashes. I imagine it must be issues with these services. For now, I solved it by disabling Clarity on my website. Many thanks for your help and follow-up.

That's very interesting! I've never heard about such issues, it would be great to see at what line it throws so that we can fight a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants