You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Changing image source and output format together reports the old image as the new crop #41
If the image source and the output format change in the same server round trip, the component reports the old image's pixels as the cropped image of the new one.
The output-format effect in image-crop.tsx (lines 202-210) calls _updateCroppedImage(crop) as soon as the component re-renders. At that point the new image has not loaded yet, so image.naturalWidth/drawImage still use the previous image. Meanwhile image.src already points to the new source, so the output type is resolved from the new image's extension (resolveOutputType(..., image.src, ...), line 339). The resulting cropped-image event is accepted by the server as the crop of the new image.
Steps to reproduce
Create an ImageCrop with image A and define a crop (user selection or setCrop).
In a single server-side handler call setImageSrc("b.jpg") and setOutputMimeType("image/jpeg") (or setOutputQuality(...)).
Call getCroppedImageDataUri() after the round trip: it holds a crop of image A, encoded as JPEG.
Expected behavior
No crop should be reported for the new image until it has loaded; then it should be re-cropped from the new image's pixels.
Possible fix
Don't re-encode until the new image has loaded, and/or tag each cropped-image event with the source of the image that was actually encoded (recorded in onLoad, not read from image.src, which already points to the new source) so the server can ignore events for a different image.
This is related to #39, which resets the cropped image when the source changes but doesn't cover this case.
Activity
fix!: reset cropped image when the image source changes