Repository navigation
Conversation
Replace react-easy-crop with @wordpress/image-editor behind the same exports: ImageCropper renders the editor canvas with a fixed crop box, and the provider keeps the editor's state and derives the hook's old shape from it. The reset state and dirtiness are the provider's own, so the editor's public API does not change for this. Quarter turns go through the editor's snap, which refits the crop and turns the pan with the image as the old cropper did; fine angles use setRotation. The package now ships a stylesheet, which includes the image editor's and removes the handle gutter the wrapper has no use for. Mounting the provider logs a deprecation notice naming @wordpress/image-editor. The README and CHANGELOG list each difference a consumer of 2.x can see. The deprecated inline image editor in block-editor keeps working: it rotates through the cropper instead of redrawing the image to a blob, drops the library's class names from its stylesheet, and loads the cropper's stylesheet.
The rebuilt hook rebuilt its setters on every state change, because they closed over the editor's controller. A consumer whose mount effect depends on setResetState, as the README example does, would then call it after every change and loop. The setters now reach the controller and the reset snapshot through refs and keep one identity, as they did before the rebuild. The canvas also shows the rule-of-thirds grid, which the old library did by default.
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. 📦 Bundle sizeSize Change: +11.5 kB (+0.13%) Total Size: 8.62 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
…wap, and getCroppedImage's source Three fixes from review: - The editor's snap reverses the stored rotation's direction when exactly one axis is flipped, so a requested rotation of 90 landed on 270. The hook now picks the snap direction from the flip, so the stored value is the number asked for. - Replacing the loaded image left the reset snapshot describing the old one, so isDirty compared the wrong images and reset applied the old pan and zoom to the new picture. The reset state is applied to the new image and the snapshot is taken again from the result. - getCroppedImage honours its src argument again, as the image to cut from, instead of ignoring it. The changelog, README and plan no longer list that deviation.
Member
Author
|
Closing in favour of deprecating the package in place: #86417. |
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.
Note
The motivation behind this PR is to remove the react-easy-crop dependency and provide a crop experience that's close and won't break apps using the
@wordpress/image-cropperpackage. Maybe we don't need to do this at all and just deprecate?What?
Stacked on:
Follow-up to #86223, part of #86145.
Rebuilds
@wordpress/image-cropperon@wordpress/image-editorbehind its existing exports, dropsreact-easy-crop, and deprecates the package in favour of@wordpress/image-editor. Also adapts the deprecated inline image editor in@wordpress/block-editor, the package's only consumer in this repository.Why?
The image editor README promised that the older cropper would be rebuilt on its maths and deprecated once it was. This removes a third-party dependency, leaves one set of cropping maths in the project, and keeps existing consumers of the package working while they move over.
How?
ImageCropperrendersImageEditorCanvaswith a fixed crop box, the grid on and the size readout off. ItsmaxZoomprop reaches the hook through provider state, default 5.ImageCropperProviderkeeps the editor's state and derives the hook's oldcropperStateshape from it:croppedAreaandcroppedAreaPixelscome frommapEditToOriginal,cropis the editor's pan. The reset state andisDirtyare the provider's own, so the editor's public API did not change for them.setRotation.build-style/style.css, which includes the image editor's stylesheet and removes the 22px handle gutter the wrapper has no use for. Consumers load it; the old library injected its own styles.sinceversion is not set yet.The differences a consumer of 2.x can notice are listed in the package CHANGELOG under Breaking Changes, and in the README under "Changes in 3.0".
Testing Instructions
@wordpress/image-editorappears once.No core block renders the inline image editor since 7.1, so it can only be exercised by a plugin that renders
wp.blockEditor.__experimentalImageEditor.2026-11-06.13.44.28.mov
Follow-ups
npm deprecateon the package when this ships.__experimentalImageEditoroff the package, or remove it, before the package itself is removed.