#66220 closed enhancement (duplicate)
Media: route media modal uploads through the client-side pipeline
| Reported by: | adamsilverstein | Owned by: | adamsilverstein |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Media | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests commit |
| Cc: | Focuses: | javascript |
Description
Follow up to #65661, which routes uploads on the Media Library grid and the "Add New Media File" screen through the client-side media processing pipeline. This ticket covers the media modal: the wp.media frame the block editor, the site editor and the block widgets screen open from an Image block's "Media Library" button, the featured image panel, and so on.
Uploads the block editor starts itself (dropping a file on a block, the inserter, the Upload button) already go through the client-side pipeline. The modal's uploader is wp.Uploader/plupload, which nothing intercepts, so it still posts the original bytes to async-upload.php. That is why the same HEIC file converts and uploads on an Image block but fails in the modal on a server with no HEIC support, and why anything uploaded through the modal skips browser-generated sub-sizes, the big image threshold and animated GIF handling.
Gutenberg currently works around this in the plugin, see https://github.com/WordPress/gutenberg/pull/82473 (https://github.com/WordPress/gutenberg/issues/82409). Core is the right home: the block editor screens are already cross-origin isolated by wp_set_up_cross_origin_isolation(), and the grid script from #65661 already binds to every wp.Uploader instance. The delta is mostly wiring:
- Rename the grid script to
media-frame-uploadand enqueue it fromwp_enqueue_media(), so it loads on every screen that opens a media frame, instead of only onupload.php. - Only enqueue it on requests
wp_set_up_cross_origin_isolation()actually isolated (newwp_is_cross_origin_isolated_request()), so screens that are not isolated, such as the Customizer and the Site Icon picker on Settings > General, do not download the pipeline bundles for a script that could only no-op. Uploads there stay on the classic path for now. - Let the shared pipeline script adopt the upload-media store when the block editor has already configured it, rather than rendering a second provider into the same store.
- Only intercept uploaders that post attachments (core's defaults:
async-upload.phpwith theupload-attachmentaction), so a plugin's ownwp.Uploaderpointed at another endpoint is left alone. This mirrors a review finding on the Gutenberg PR.
Not covered here, worth their own tickets once this lands: isolating the Customizer (its preview iframe needs same-origin access that Document-Isolation-Policy would block), the Site Icon picker, and the classic editor's media modal.
Patch incoming.
Attachments (1)
Change History (9)
This ticket was mentioned in PR #13875 on WordPress/wordpress-develop by @adamsilverstein.
7 weeks ago
#1
#3
@
7 weeks ago
## Test Report
### Environment
- OS: Linux
- Browser: Chrome (version)
- Local: wordpress-develop @ PR 13875
### Results
- [x] PHPUnit filter: OK (70 tests, 108 assertions)
- [x] Media modal upload via Image block -> Network shows wp/v2/media include with
)]] sideload/finalize, no async-upload.php
- [x] crossOriginIsolated === true
#4
follow-up:
↓ 6
@
5 weeks ago
- Milestone 7.2 → 7.3
As per today’s pre-beta 1 scrub: this is stacked on #65661, which hasn’t landed yet, and with beta 1 close, I’m moving this to 7.3.
@adamsilverstein, feel free to move it back if it needs to be in this milestone.
#6
in reply to: ↑ 4
@
4 weeks ago
- Milestone 7.3
- Resolution → duplicate
- Status assigned → closed
Replying to im3dabasia1:
As per today’s pre-beta 1 scrub: this is stacked on #65661, which hasn’t landed yet, and with beta 1 close, I’m moving this to 7.3.
@adamsilverstein, feel free to move it back if it needs to be in this milestone.
@im3dabasia1 - turns out I can just squash this down to a single commit and trac ticket, no changes are required on the Gutenberg side so splitting this out isn't really needed.
I'm going to close this trac ticket in favor of https://core.trac.wordpress.org/ticket/65661 and continue the work there.
@adamsilverstein commented on PR #13875:
4 weeks ago
#7
Folded into #12585, which now carries the media modal work as well, so closing this one in favor of it.
Stacked on https://github.com/WordPress/wordpress-develop/pull/12585 - only the last commit is new here, everything before it is that PR. Once #12585 lands this rebases down to the one commit.
Description
#12585 routes uploads on the Media Library grid and the "Add New Media File" screen through the client-side media processing pipeline. The media modal - the
wp.mediaframe the block editor, the site editor and the block widgets screen open from an Image block's "Media Library" button, the featured image panel and so on - still uploads throughwp.Uploader/plupload toasync-upload.php. That is why a HEIC file converts and uploads when dropped on an Image block but fails in the modal on a server with no HEIC support, and why anything uploaded through the modal skips browser-generated sub-sizes, the big image threshold and animated GIF handling. Gutenberg currently works around this in the plugin (https://github.com/WordPress/gutenberg/pull/82473); this PR gives it a home in core.The block editor screens are already cross-origin isolated by
wp_set_up_cross_origin_isolation(), and the grid script from #12585 already binds to everywp.Uploaderinstance, so the delta is mostly wiring:media-library-uploadtomedia-frame-uploadand enqueue it fromwp_enqueue_media(), so it loads on every screen that opens a media frame instead of only onupload.php. The grid keeps working through the same call.wp_set_up_cross_origin_isolation()actually isolated, via a newwp_is_cross_origin_isolated_request(). Screens that are not isolated - the Customizer, the Site Icon picker on Settings > General, the classic editor - load the media frame too, but they would download the wholewp-upload-mediachain for a script that can only no-op there. Their uploads stay on the classic path for now.mediaSideloadandmediaFinalizehave no defaults) instead of "this script's own settings landed", since the block editor's provider can render after ours and replace them with equivalent ones.async-upload.phpwith theupload-attachmentaction - so a plugin's ownwp.Uploaderpointed at another endpoint is left alone. This mirrors a review finding from @andrewserong on the Gutenberg PR.Not covered here, worth their own tickets once this lands: isolating the Customizer (its preview iframe needs same-origin access that Document-Isolation-Policy would block), the Site Icon picker, and the classic editor's media modal.
Testing Instructions
[[Image(https://img.shields.io/badge/Test_in-WP_Playground-blue?style=for-the-badge&logo=wordpress)]]
_Test in Chrome 137 or newer on a secure origin (https or localhost)._
wp/v2/media, then sideload and finalize requests, and no POST toasync-upload.php. The tile's progress bar advances, the finished tile is selectable, and "Select" inserts it into the block as usual.Document-Isolation-Policyheader blocked in DevTools: the upload goes throughasync-upload.phpas before.async-upload.php, andmedia-frame-upload.jsis not loaded on the page.Automated coverage, all green locally:
npm run test:php -- --filter 'wpEnqueueMediaFrameUpload|wpEnqueueMediaNewUpload|CrossOriginIsolation'- 76 tests, including four new ones for the isolated-request gate and thewp_enqueue_media()enqueue.npm run test:e2e -- media-modal-client-side-upload media-library-client-side-upload media-new-client-side-upload- 31 tests. The new modal spec checks the script loads in the block editor, that an upload from the modal goes create, sideload, finalize with nothing hittingasync-upload.phpand the finished image lands in the block, and that stripping the isolation header falls back to the classic uploader.AI Use
Claude Code did the typing here, I did the asking. I will review and test.
🤖 Generated with Claude Code
https://claude.ai/code/session_015q272S5jKgWCuQYrbz2SKb