Croppie icon indicating copy to clipboard operation
Croppie copied to clipboard

`croppie.destroy()` causes errors

Open diachedelic opened this issue 7 years ago • 12 comments

Error 1

// This error happens because `opts.update()` is called after `destroy()`

Uncaught (in promise) TypeError: Cannot read property 'preview' of undefined
    at Croppie._get (webpack-internal:///223:1318:37)
    at Croppie._result (webpack-internal:///223:1353:25)
    at Croppie.result (webpack-internal:///223:1569:28)

Error 2

// This error happens because `_updateOverlay()` is triggered by `_debouncedOverlay()`
// after a `destroy()`, and `self.elements` is null

Uncaught TypeError: Cannot read property 'boundary' of undefined
    at Croppie._updateOverlay (croppie.js?f101:939)
    at later (croppie.js?f101:102)
function _updateOverlay() {
        var self = this,
            boundRect = self.elements.boundary.getBoundingClientRect(),
            imgData = self.elements.preview.getBoundingClientRect();
...
}

diachedelic avatar Nov 02 '17 03:11 diachedelic

Good catch. I guess the simplest fix would be adding a

if (!self.elements) return;

at the top of the _updateOverlay.

thedustinsmith avatar Nov 17 '17 13:11 thedustinsmith

Yes, shall I do that and submit a PR?

diachedelic avatar Nov 20 '17 02:11 diachedelic

Will that fix the first error though?

diachedelic avatar Nov 20 '17 02:11 diachedelic

I'm not seeing the first error you mentioned. Where is opts.update called after destroy?

thedustinsmith avatar Dec 08 '17 14:12 thedustinsmith

Hmm I can't replicate this atm, but possibly if the croppie was destroyed while waiting for loadImage() in _bind()?

diachedelic avatar Dec 09 '17 01:12 diachedelic

Then _triggerUpdate() is called after croppie has been destroyed, which calls self.options.update()

diachedelic avatar Dec 09 '17 01:12 diachedelic

Despite using this if (!self.elements) return; at the top of _updateOverlay(), I am getting the error "Cannot read property 'preview' of undefined" at Croppie_get().

and in Croppie_destroy(), I am getting this error when I am trying to destroy an existing instance post uploading an image.

iamchirag avatar Aug 17 '18 09:08 iamchirag

Please guyz, Can you help me out asap. I am using it in my company project and deadline is this Sunday. Please have a look and comment to help.

iamchirag avatar Aug 17 '18 09:08 iamchirag

Hey guyz, i was getting the error because _croppie_instance.destroy() was not working. Set it to null and then initiated Croppie instance and it started working.

iamchirag avatar Aug 17 '18 10:08 iamchirag

I was encountering this because I had moved one of the Croppie components (the zoom slider) from the Croppie container into our container.

Calling destroy() with some Croppie elements intentionally placed elsewhere in the DOM threw an error. It looked like Croppie was trying to search for known children and couldn't find them in the original parent container.

When I put the slider back into the original Croppie container, then proceed to can call destroy(), the instance is destroyed without error.

ckmahoney avatar May 30 '19 16:05 ckmahoney

Any fix on that?

guilhermebentomarques avatar Sep 30 '21 13:09 guilhermebentomarques

Anybody fix on this problem?

whatsnow avatar Nov 24 '21 19:11 whatsnow