Repository navigation
Conversation
…loads With an `image_editor_output_format` filter, the server converted the main file of client side uploads, and the browser then replaced it with its own scaled or rotated image. The sideload recorded the server's converted copy as `original_image`, so the upload stayed on disk after a permanent delete. The server now leaves the main file unconverted. When the image isn't scaled, the browser sideloads a full size converted copy as the `original`, rotated if needed, so only one sideload replaces the main file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @b1ink0! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for working on this @b1ink0, moving the main file conversion to the browser makes sense to me and the I had Claude review and test this one locally, here is what it found:
Does the |
…he sub-sizes. The HEIC canvas fallback uploads with `generate_sub_sizes` set to true, so the server already scales and converts the main file. The client then sideloaded a second `scaled` or `original` file over it, and the uploaded file was left on disk after a permanent delete. The main file sideloads now only run for uploads sent with `generate_sub_sizes` set to false. Adds unit tests for the main file sideloads, a test for the converted file name reservation, and explains in `create_item()` why the filter is added on `add_attachment`. Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for testing this, @adamsilverstein. The HEIC fallback regression is real.
Yes. For the other points:
|
…ain file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rsion e2e tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What?
Follow up to #75793 and #80295.
Makes the browser the only place that writes the main file of a client side upload. The server no longer converts it when the output format is filtered.
This should be merged after #83785, and rebased on it.
Why?
Core ticket: https://core.trac.wordpress.org/ticket/66763
With an
image_editor_output_formatfilter (for example JPEG to WebP), two places write the main file of a client side upload. The server convertsphoto.jpgtophoto.webpin the upload request, then the browser'sscaledsideload (big images) or rotatedoriginalsideload (EXIF rotated images) replaces it again. The sideload records the file it replaces,photo.webp, asoriginal_image. Nothing points atphoto.jpganymore, so it stays on disk after "Delete permanently".The server converts the main file because of #75793. At the time, an
originalsideload only setoriginal_imageand didn't replace the main file, so the browser couldn't supply a converted main file. #80295 changed that, so the workaround is no longer needed.How?
create_item()turns off main file conversion for uploads withgenerate_sub_sizesset to false, once the upload is stored. The upload's name still reserves the names of the converted files. If another attachment already hasphoto.webp, the upload is saved asphoto-1.jpgand its converted copy asphoto-1.webp.generateThumbnails()sideloads a full size converted copy as theoriginal, rotated if the EXIF orientation needs it. The rotatedoriginalis only sent when there's no conversion. So at most one sideload replaces the main file.scaledororiginalsideload replaces the main file with an image in another format, the sideload also updates the attachment's MIME type, so aphoto.webpmain file is no longer reported asimage/jpeg(#53665). The e2e tests for format conversion now expect the converted MIME type.Core counterpart: WordPress/wordpress-develop#16119
Testing Instructions
photo.jpg,photo.webpand the WebP sub sizes, and that the Media Library showsphoto.webpas the file andimage/webpas the file type.photofiles are left in the uploads folder.photo.jpgandphoto-scaled.webpand nophoto.webp, and that nothing is left after a permanent delete.photo.webp, shown upright, and that nothing is left after a permanent delete.Testing Instructions for Keyboard
No UI changes.
Screenshots or screencast
Big image before:
trunk-big.mp4
Big image after:
after-big.mp4
Rotated image before:
trunk-phone.mp4
Rotated image after:
after-phone.mp4
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Tracing the upload flow, a script that replays the client's REST requests, and drafts of the fix. I reviewed, edited and tested the final changes.
🤖 Generated with Claude Code