fix(@uppy/image-editor): destroy cropper and clean up state on file re-open and removal#6223
Open
alexh-humanitix wants to merge 1 commit intotransloadit:mainfrom
Open
Conversation
🦋 Changeset detectedLatest commit: fe290e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…e-open and removal When opening the image editor for a second file (e.g. drag file → save in editor → clear → drag new file), the old Cropper instance was not destroyed. This caused `initCropper()` to bail early (`if (this.cropper) return`), leaving the new image with a stale cropper that retained the previous file's crop dimensions and referenced a destroyed DOM element. Additionally, when a file was removed from the Dashboard, the ImageEditor plugin had no handler to clean up its internal state (currentImage, cropper, objectUrl), so everything persisted into the next editing session. Changes: - Call `this.destroyCropper()` at the top of `start()` to tear down any previous cropper before initializing a new editing session - Add a `file-removed` event listener (registered in `install()`, cleaned up in `uninstall()`) that calls `stop()` when the currently-edited file is removed from Uppy
818d5d1 to
fe290e3
Compare
Contributor
|
shouldn't cropper reset happen inside |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6210
Problem
When using the ImageEditor with the Dashboard, the following sequence causes the editor to break on the second file:
Expected: The image editor works normally in subsequent edits.
Actual: The image preview and actions show, but the cropper doesn't initialize properly, so no edits can be made.
Root Cause
Two cleanup gaps in
ImageEditor:start()doesn't destroy the previous cropper. It revokes the oldobjectUrlbut leaves theCropperinstance alive. When theEditorcomponent mounts for the new file and callsinitCropper(imgElement), it hits the early returnif (this.cropper) returnand never creates a new cropper — the stale instance retains the old file's crop dimensions and references a destroyed DOM element.No
file-removedlistener. When a file is removed from the Dashboard, the ImageEditor has no handler to clean up its state (currentImage, cropper, objectUrl, event listeners), so everything persists into the next editing session.Fix
this.destroyCropper()at the top ofstart()to fully tear down any previous cropper before starting a new editing sessionhandleFileRemovedlistener (registered ininstall(), deregistered inuninstall()) that callsstop()when the currently-edited file is removed from UppyChanges
packages/@uppy/image-editor/src/ImageEditor.tsx— 10 insertions, 1 deletionTest Plan
autoOpen="imageEditor")