Client-side media processing: only use media upload provider at the top level of the block editor provider#76124
Conversation
|
The fix looks fine for now @andrewserong - I guess a separate function makes sense as a broader solution unless you have other ideas to try? |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If 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. |
|
Size Change: +41 B (0%) Total Size: 6.87 MB
ℹ️ View Unchanged
|
Yeah, that's the only thing I could think of — something like I gotta run for the day, but I've kicked off a failing e2e test in case it's just a transient error. If it's real, though, I can dig in further tomorrow. Thanks for the speedy review! |
|
Thanks for the quick fix! On trunk, I couldn't do this on a page or in the site editor: Kapture.2026-03-04.at.17.42.47.mp4On this branch 👍🏻 |
| // | ||
| // Only the top-level (non-preview) provider should do this. | ||
| // Nested preview providers (e.g. from useBlockPreview in | ||
| // core/post-template) inherit settings that already contain |
There was a problem hiding this comment.
Ah, so would not being able to upload images on a "page" post type be due to the template it's using (in TT5)?
ramonjd
left a comment
There was a problem hiding this comment.
Excellent sleuthing! Tested across the editors and this works for me in all contexts.
The e2e fail doesn't look related to this change, but it also fails for me locally.
test/e2e/specs/site-editor/user-global-styles-revisions.spec.js:136:2 › Style Revisions › should access from the site editor sidebar
I've kicked them off again. If they keep failing we can look into it.
Because I had revisions in my test db and forgot to |
| if ( isClientSideMediaEnabled && _settings?.mediaUpload ) { | ||
| if ( | ||
| isClientSideMediaEnabled && | ||
| _settings?.mediaUpload && |
There was a problem hiding this comment.
Part of the existing condition here is settings.mediaUpload needs to be defined for client side media processing to work. I found that curious, is this because client side media processing eventually calls through to the vanilla server version of mediaUpload?
I think an alternative fix might be to make mediaUpload undefined for BlockPreview. Users shouldn't be uploading media in previews anyway. That would avoid the need for extra isPreview checks (though would still need to do something to avoid rendering the provider, it could work the same).
There was a problem hiding this comment.
Here's where it could be implemented -
gutenberg/packages/block-editor/src/components/block-preview/index.js
Lines 59 to 66 in d37cda8
There was a problem hiding this comment.
I think an alternative fix might be to make mediaUpload undefined for BlockPreview.
Just a drive-by comment before I close my laptop for the day: setting it to undefined for BlockPreview results in the function not being available within upload-media and throws an error (as in this context, it'll wind up updating the shared settings used across the media upload provider). (I tried that approach first, but didn't get very far — I do like the idea of trying to simplify things, though 🤔 )
I think a separate fix would be to untangle the re-use of the same key (i.e. call the "real" upload function something different within upload-media), but that's a bit beyond the scope of the quick fix.
It's a little convoluted this!
There was a problem hiding this comment.
Ideally none of the upload-media code executes for block previews at all, so then there would never be an opportunity to throw an error. 😄
There was a problem hiding this comment.
Ideally none of the upload-media code executes for block previews at all, so then there would never be an opportunity to throw an error. 😄
Good point! 😄
Hrm, weirdly it does seem to be failing consistently, though. I'll do some more digging tomorrow! |
|
@andrewserong - #76137 is an alternate take based on your suggestion of using separate keys. I'm not certain it fixes your issue. |
894ace6 to
ec1117e
Compare
|
It turns out the e2e test failure was legit as in the site editor To try to fix this, I've adjusted the logic so that instead of checking if we're in preview mode, we instead attempt to only intercept the This fix is trying to find a sweet spot between what I originally tried here and @adamsilverstein's alternative in #76137 which added a separate key for the server upload function but in testing seemed to cause issues for sideloading. I'm still not 100% sure this is the right fix as I think things could be untangled further / made clearer, but so far this is still testing well for me locally. Now to see what the e2e tests think 🤔 |
|
That seemed to do the trick. I'll aim to merge this one once the performance tests pass. |
… in preview mode (#76124) * Client-side media processing: only use media upload provider when not in preview mode * Expand on comments * Try using a key on the intercepted function instead Co-authored-by: andrewserong <[email protected]> Co-authored-by: adamsilverstein <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: talldan <[email protected]>
|
I just cherry-picked this PR to the wp/7.0 branch to get it included in the next release: c913b7d |
CI run: #11167. See #64595. --- I've included a log of the Gutenberg changes with the following command: git log --reverse --format="- %s" 022d8dd3d461f91b15c1f0410649d3ebb027207f..e499abfb843a43ac88455ca319220c5f181e1cf3 | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy - Add documentation for contentRole and listView block supports (WordPress/gutenberg#75903) - Interactivity Router: fix back and forward navigation after refresh (WordPress/gutenberg#75927) - Real-time collaboration: Fix disconnect dialog on navigate (WordPress/gutenberg#75886) - Real Time Collab: Throttle syncing for inactive tabs. (WordPress/gutenberg#75843) - Components: Specify line-height to avoid inheriting default values (WordPress/gutenberg#75880) - Pattern Editing: Fix sibling blocks to edited pattern not being disabled (WordPress/gutenberg#75994) - Sync connector PHP behavior with Core backport changes (WordPress/gutenberg#75968) - Connectors: Avoid manual string concatenation (WordPress/gutenberg#75997) - DataForm: fix field label for panel (should not be uppercase) (WordPress/gutenberg#75944) - Views: add support for more overrides (all developer-defined config) (WordPress/gutenberg#75971) - Use homeUrl instead of siteUrl for link badge evaluations (WordPress/gutenberg#75978) - DataViews: Right-align `integer` and `number` fields (WordPress/gutenberg#75917) - Navigation Link: Compare internal links by host instead of origin (WordPress/gutenberg#76015) - Fix: Skip scaled image sideload for images below big image threshold (WordPress/gutenberg#75990) - Client side media cherry pick for 7.0 (WordPress/gutenberg#75998) - Show transform dropdown previews on focus as well as hover (WordPress/gutenberg#75940) (WordPress/gutenberg#75992) - RTC: Fix syncing of emoji / surrogate pairs (WordPress/gutenberg#76049) - [Real-time Collaboration] Fix sync issue on refresh (WordPress/gutenberg#76017) - Real-time collaboration: Improve disconnect dialog (WordPress/gutenberg#75970) - DataViews: Fix filter toggle flickering when there are locked or primary filters (WordPress/gutenberg#75913) (WordPress/gutenberg#76068) - Connectors: Dynamically register providers from WP AI Client registry (WordPress/gutenberg#76014) - PHP-only Blocks: Reflect bound attribute values in inspector controls (WordPress/gutenberg#76040) - Fix: Set quality and strip metadata in client-side image resize (WordPress/gutenberg#76029) - RTC: Prevent duplicate poll cycles (WordPress/gutenberg#76059) - RTC: Fix stale CRDT document persisted on save (WordPress/gutenberg#75975) - RTC: Disable multiple collaborators if meta boxes are present (WordPress/gutenberg#75939) - Directly inject styles in overlay to make styles stay consistently mounted (WordPress/gutenberg#75700) - Real-time collaboration: Fix comment syncing on site editor (WordPress/gutenberg#75746) - Real-time Collaboration: Bug fix for CRDT user selection and add tests (WordPress/gutenberg#75075) - RTC: Updates from backport PR (WordPress/gutenberg#75711) - RTC: Fix undefined array_first() call in sync storage (WordPress/gutenberg#75869) - RTC: Fix fallthrough for sync update switch statement (WordPress/gutenberg#76060) - Real-time collaboration: Remove block client IDs from Awareness, fix "Show Template" view (WordPress/gutenberg#75590) - RTC: Add session activity notifications (WordPress/gutenberg#76065) - Prevent non-reproducible Sass/CSS builds. (WordPress/gutenberg#76098) - Block toolbar and context menu: hide pattern actions in Revisions UI (WordPress/gutenberg#76066) - Try enabling style variation transforms for blocks in contentOnly mode (WordPress/gutenberg#75761) - Block toolbar: hide styles dropdown in Revisions UI (WordPress/gutenberg#76119) - Image block: fix lightbox srcset size (WordPress/gutenberg#76092) - Fix writing flow navigation for annotation style, or any other block with border radius (WordPress/gutenberg#76072) - Image: Hide 'Set as featured image' for in-editor revisions (WordPress/gutenberg#76123) - Connectors: Gate unavailable install actions behind install capability (WordPress/gutenberg#75980) - build: Exclude experimental pages from Core builds (WordPress/gutenberg#76038) - HTML & Shortcode: Disable viewport visibility support (WordPress/gutenberg#76138) - RTC: Verify client ID to avoid awareness mutation (WordPress/gutenberg#76056) - wp-build: Do not remove Core's default script modules registration (WordPress/gutenberg#75705) - wp-build: Deregister script modules before re-registering (WordPress/gutenberg#75909) - Remove `! function_exists()` checks from PHP templates (WordPress/gutenberg#76062) - Connectors: Update page identifier to options-connectors (WordPress/gutenberg#76156) - Connectors: Align init hook priorities with Core overrides (WordPress/gutenberg#76161) - Icon Block: Clean up selectors config (WordPress/gutenberg#75786) - Icons: Fix incorrect icon slug (WordPress/gutenberg#76165) - RTC: Enable RTC by default (WordPress/gutenberg#75739) - Rename and visibility modals: gate shortcuts behind canEditBlock to prevent triggering in revisions UI (WordPress/gutenberg#76168) - Fix: Block style variations not rendering in Site Editor Patterns page (WordPress/gutenberg#76122) - Client-side media processing: only use media upload provider when not in preview mode (WordPress/gutenberg#76124) - Notes: Disable for in-editor revisions (WordPress/gutenberg#76180) - Core Data: Support reading revision data in useEntityProp (fixes footnotes in revisions UI) (WordPress/gutenberg#76106) - Client-side media processing: Try plumbing invalidation to the block-editor's mediaUpload onSuccess callback (WordPress/gutenberg#76173) - Connectors: Improve responsive layout on small screens (WordPress/gutenberg#76186) - Interactivity API: Fix router initialization race condition on Safari/Firefox (WordPress/gutenberg#76053) (WordPress/gutenberg#76191) - Interactivity: Fix crypto.randomUUID crash in non-secure contexts (WordPress/gutenberg#76151) git-svn-id: https://develop.svn.wordpress.org/trunk@61843 602fd350-edb4-49c9-b593-d223f7449a82
CI run: WordPress/wordpress-develop#11167. See #64595. --- I've included a log of the Gutenberg changes with the following command: git log --reverse --format="- %s" 022d8dd3d461f91b15c1f0410649d3ebb027207f..e499abfb843a43ac88455ca319220c5f181e1cf3 | sed 's|#\([0-9][0-9]*\)|https://github.com/WordPress/gutenberg/pull/\1|g; /github\.com\/WordPress\/gutenberg\/pull/!d' | pbcopy - Add documentation for contentRole and listView block supports (WordPress/gutenberg#75903) - Interactivity Router: fix back and forward navigation after refresh (WordPress/gutenberg#75927) - Real-time collaboration: Fix disconnect dialog on navigate (WordPress/gutenberg#75886) - Real Time Collab: Throttle syncing for inactive tabs. (WordPress/gutenberg#75843) - Components: Specify line-height to avoid inheriting default values (WordPress/gutenberg#75880) - Pattern Editing: Fix sibling blocks to edited pattern not being disabled (WordPress/gutenberg#75994) - Sync connector PHP behavior with Core backport changes (WordPress/gutenberg#75968) - Connectors: Avoid manual string concatenation (WordPress/gutenberg#75997) - DataForm: fix field label for panel (should not be uppercase) (WordPress/gutenberg#75944) - Views: add support for more overrides (all developer-defined config) (WordPress/gutenberg#75971) - Use homeUrl instead of siteUrl for link badge evaluations (WordPress/gutenberg#75978) - DataViews: Right-align `integer` and `number` fields (WordPress/gutenberg#75917) - Navigation Link: Compare internal links by host instead of origin (WordPress/gutenberg#76015) - Fix: Skip scaled image sideload for images below big image threshold (WordPress/gutenberg#75990) - Client side media cherry pick for 7.0 (WordPress/gutenberg#75998) - Show transform dropdown previews on focus as well as hover (WordPress/gutenberg#75940) (WordPress/gutenberg#75992) - RTC: Fix syncing of emoji / surrogate pairs (WordPress/gutenberg#76049) - [Real-time Collaboration] Fix sync issue on refresh (WordPress/gutenberg#76017) - Real-time collaboration: Improve disconnect dialog (WordPress/gutenberg#75970) - DataViews: Fix filter toggle flickering when there are locked or primary filters (WordPress/gutenberg#75913) (WordPress/gutenberg#76068) - Connectors: Dynamically register providers from WP AI Client registry (WordPress/gutenberg#76014) - PHP-only Blocks: Reflect bound attribute values in inspector controls (WordPress/gutenberg#76040) - Fix: Set quality and strip metadata in client-side image resize (WordPress/gutenberg#76029) - RTC: Prevent duplicate poll cycles (WordPress/gutenberg#76059) - RTC: Fix stale CRDT document persisted on save (WordPress/gutenberg#75975) - RTC: Disable multiple collaborators if meta boxes are present (WordPress/gutenberg#75939) - Directly inject styles in overlay to make styles stay consistently mounted (WordPress/gutenberg#75700) - Real-time collaboration: Fix comment syncing on site editor (WordPress/gutenberg#75746) - Real-time Collaboration: Bug fix for CRDT user selection and add tests (WordPress/gutenberg#75075) - RTC: Updates from backport PR (WordPress/gutenberg#75711) - RTC: Fix undefined array_first() call in sync storage (WordPress/gutenberg#75869) - RTC: Fix fallthrough for sync update switch statement (WordPress/gutenberg#76060) - Real-time collaboration: Remove block client IDs from Awareness, fix "Show Template" view (WordPress/gutenberg#75590) - RTC: Add session activity notifications (WordPress/gutenberg#76065) - Prevent non-reproducible Sass/CSS builds. (WordPress/gutenberg#76098) - Block toolbar and context menu: hide pattern actions in Revisions UI (WordPress/gutenberg#76066) - Try enabling style variation transforms for blocks in contentOnly mode (WordPress/gutenberg#75761) - Block toolbar: hide styles dropdown in Revisions UI (WordPress/gutenberg#76119) - Image block: fix lightbox srcset size (WordPress/gutenberg#76092) - Fix writing flow navigation for annotation style, or any other block with border radius (WordPress/gutenberg#76072) - Image: Hide 'Set as featured image' for in-editor revisions (WordPress/gutenberg#76123) - Connectors: Gate unavailable install actions behind install capability (WordPress/gutenberg#75980) - build: Exclude experimental pages from Core builds (WordPress/gutenberg#76038) - HTML & Shortcode: Disable viewport visibility support (WordPress/gutenberg#76138) - RTC: Verify client ID to avoid awareness mutation (WordPress/gutenberg#76056) - wp-build: Do not remove Core's default script modules registration (WordPress/gutenberg#75705) - wp-build: Deregister script modules before re-registering (WordPress/gutenberg#75909) - Remove `! function_exists()` checks from PHP templates (WordPress/gutenberg#76062) - Connectors: Update page identifier to options-connectors (WordPress/gutenberg#76156) - Connectors: Align init hook priorities with Core overrides (WordPress/gutenberg#76161) - Icon Block: Clean up selectors config (WordPress/gutenberg#75786) - Icons: Fix incorrect icon slug (WordPress/gutenberg#76165) - RTC: Enable RTC by default (WordPress/gutenberg#75739) - Rename and visibility modals: gate shortcuts behind canEditBlock to prevent triggering in revisions UI (WordPress/gutenberg#76168) - Fix: Block style variations not rendering in Site Editor Patterns page (WordPress/gutenberg#76122) - Client-side media processing: only use media upload provider when not in preview mode (WordPress/gutenberg#76124) - Notes: Disable for in-editor revisions (WordPress/gutenberg#76180) - Core Data: Support reading revision data in useEntityProp (fixes footnotes in revisions UI) (WordPress/gutenberg#76106) - Client-side media processing: Try plumbing invalidation to the block-editor's mediaUpload onSuccess callback (WordPress/gutenberg#76173) - Connectors: Improve responsive layout on small screens (WordPress/gutenberg#76186) - Interactivity API: Fix router initialization race condition on Safari/Firefox (WordPress/gutenberg#76053) (WordPress/gutenberg#76191) - Interactivity: Fix crypto.randomUUID crash in non-secure contexts (WordPress/gutenberg#76151) Built from https://develop.svn.wordpress.org/trunk@61843 git-svn-id: http://core.svn.wordpress.org/trunk@61130 1a063a9b-81f0-0310-95a4-ce76da25c4cd
… in preview mode (#76124) * Client-side media processing: only use media upload provider when not in preview mode * Expand on comments * Try using a key on the intercepted function instead Co-authored-by: andrewserong <[email protected]> Co-authored-by: adamsilverstein <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: talldan <[email protected]>
|
I just cherry-picked this PR to the release/22.7 branch to get it included in the next release: 9274c94 |
What?
Part of:
Fix a bug where images uploaded to an image block in the site editor would get stuck in an endless loading state without uploading.
Why?
In the site editor when we're editing a template we typically have a Query Loop / Post Template block somewhere in the template rendering a block preview. When a block preview is present, a nested
ExperimentalBlockEditorProvideris rendered, and this causes a problem — because the nested provider's access to its block editor settings uses the overriddenmediaUploadfunction that simply queues items for upload, instead of actually uploading to the server.Because the
MediaUploadProviderdoes not use a sub-registry, when we update the media upload settings, the upload-media store gets stuck in a state where subsequent calls tomediaUploadsimply queue more images for upload without an upload ever occurring. The result is: endlessly stuck in a loading / pending state.It's hard to describe the issue: but effectively the upload-media store gets stuck in a state where it no longer has access to the "real"
mediaUploadthat uploads to the server.This idea in this PR is to do something of a quick fix — skip outputting theMediaUploadProviderand overridingmediaUploadif we're in a preview state. As a bandaid and to fix the issue in 7.0, I think this is a reasonable fix for now.This PR adds a
__isMediaUploadInterceptorkey to the interceptedmediaUploadso that we only outputMediaUploadProviderin the outer-mostBlockEditorProviderto prevent getting stuck.More broadly, though, I'm wondering if there's a better API for the internals of
upload-mediato avoid the problem that the server-sidemediaUpload(that is, the function that actually submits the media to the server) has the same key as themediaUploadthat adds items to the queue.I.e. possibly we could have a separate function... but that feels like a bit more of a rabbit hole than fixing the task at hand. So I've tried to keep things simple, while adding lots of comments to explain the issue.
If there's a better approach, though, happy to close this out!
How?
mediaUploadand outputtingMediaUploadProviderwhen the block editor settings are not at the top-level (i.e. when the passed in_settings?.mediaUploadis the intercepted version)Testing Instructions
On trunk:
With this PR:
Note: there is a separate issue with what happens when an upload completes (it appears like it's an external image). There's a separate fix for this over in: #76121
Screenshots or screencast
Before
You'd just get stuck in this state endlessly:
After
Upload completes successfully:
2026-03-04.17.03.21.mp4