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

The cropperImage.$ready()is called without it being ready. #1168

Open
genu opened this issue Apr 30, 2024 · 2 comments
Open

The cropperImage.$ready()is called without it being ready. #1168

genu opened this issue Apr 30, 2024 · 2 comments

Comments

@genu
Copy link

genu commented Apr 30, 2024

Describe the bug
I think there is a weird race condition happening when trying to set initia values after image has loaded.

I'm implementing V2 in vue as so:

onMounted(async () => {
  await nextTick();

  await cropperImage.value!.$ready();
  cropperImage.value!.$center('contain').$zoom(-0.1); // <--- Doesn't work
  setTimeout(() => {
    cropperImage.value!.$center('contain').$zoom(-0.1); <-- // Works
  }, 0);
});

Expected behavior
I expect that after calling $ready I should be able to performa any action on image

Desktop (please complete the following information):

  • OS: MacOS
  • Browser safar
@fengyuanchen
Copy link
Owner

fengyuanchen commented May 4, 2024

How about this:

onMounted(async () => {
  await nextTick();
  await cropperImage.value!.$ready();
  await nextTick(); // Wait for next tick
  cropperImage.value!.$center('contain').$zoom(-0.1); // <--- Does it work?
});

@rhys-dm
Copy link

rhys-dm commented Sep 11, 2024

I had occasional glitches with code such as this.

cropper.getCropperImage().$ready(
          (image) => {
            image.addEventListener("load", (_) => {
              console.log("maybe ready");
            });
          }
        );

Now it's deferring to nextTick which, so far, has fewer glitches.

cropper.getCropperImage().$ready((_) => {
          nextTick(this, () => {
              console.log("maybe ready");
          });
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants