Repository navigation
Conversation
With client side media processing and an `image_editor_output_format` filter, the server converted the main file of the upload, and the browser then replaced it with its own scaled or rotated image. The sideload recorded the converted copy as `original_image`, so the upload stayed on disk after the attachment was deleted permanently. The main file of these uploads is now left unconverted, and the browser supplies the converted main file through the sideload endpoint. The output format filter is turned off only once the upload is stored, so its name still reserves the names of the converted files. Follow-up to [62805], [63014]. Fixes #66763. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: 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:
|
I believe thats expected behavior - the original upload is always saved. we may called the -scaled version "original_image" in meta so it gets served that way, but under the hood the original upload is a different image preserved under a different key, likely source_image. we may output a second image in a new format and call that the "original_image", but we always preserve the actual original. One big reason we always preserve the original is so that users can always regenerate their images as needed, from the source. |
|
|
||
| // The client sideloads the converted main file. | ||
| if ( false === $request['generate_sub_sizes'] ) { | ||
| add_filter( 'image_editor_output_format', '__return_empty_array', 100 ); |
There was a problem hiding this comment.
hmmm, i'm not sure disabling the filtered mapping is the best solution here, how else could we fix this?
Can we make this change at a different part of the stack?
There was a problem hiding this comment.
how else could we fix this? Can we make this change at a different part of the stack?
The mapping is still used. The upload response still returns image/webp as image_output_format (the new test checks that), and the browser uses it to convert the main file and the sub sizes. This filter only stops the server from converting the main file during the upload request, so the server stores only the original, as you described on the ticket. It's the same filter convert_format: false already adds in create_item().
The other part of the stack is the client: WordPress/gutenberg#87135 makes the browser create the converted main file, which the server used to make.
I also tried a server only fix: keep the server's conversion, and when the browser's scaled or rotated main file arrives in sideload_item(), keep photo.jpg as original_image and delete the server's photo.webp. That stops the leak too, but the server still converts every upload at full size only to delete it, which is the work client side processing is meant to move to the browser.
Agreed that the upload is always saved, and with both PRs it is. The sentence you quoted was unclear, sorry. By "main file" I meant the file the attachment serves, not the upload. I've reworded it in the description. One thing about the keys: the served file is the attached file, and More detail on the ticket: https://core.trac.wordpress.org/ticket/66763#comment:8 |
|
Thanks for the detailed replies @b1ink0, that clears up my confusion about the keys - the attached file is what gets served and Claude ran the uploads on each path and compared the results:
Does the plan to land both together work for you? I'd rather not have the core change go in first. |
With client side media processing and an
image_editor_output_formatfilter, the server converted the main file of the upload, for examplephoto.jpgtophoto.webp. The browser then replaced the main file with its ownscaledor rotated image, and the sideload recordedphoto.webpasoriginal_image. Nothing pointed atphoto.jpganymore, so it stayed on disk after "Delete permanently".When
generate_sub_sizesis false,create_item()now leaves the main file unconverted, using the same filter asconvert_format: false. The browser supplies the converted main file through the sideload endpoint, so only one place writes the main file. The filter is added after the upload is stored, so 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.The new test uploads a JPEG with a JPEG to WebP filter and checks that the upload stays the attached file, that no WebP copy is written, and that the response still asks the client for WebP.
This needs the client change from WordPress/gutenberg#87135 in the same release. That change makes the browser create the converted main file for every image that needs a new format, not only for scaled or rotated ones. Without it, the served file of an image under the big image size threshold stays in the uploaded format, for example
photo.jpginstead ofphoto.webp. The upload itself is always kept, either as the served file or asoriginal_image.Trac ticket: https://core.trac.wordpress.org/ticket/66763
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.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code