Repository navigation
Conversation
|
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. |
antwonw
force-pushed
the
fix/media-replace-flow-on-success
branch
from
September 21, 2026 19:13
08a4581 to
1e19e93
Compare
Contributor
Author
|
Could a maintainer please add the |
antwonw
force-pushed
the
fix/media-replace-flow-on-success
branch
from
September 21, 2026 19:38
1e19e93 to
5cf81d5
Compare
antwonw
force-pushed
the
fix/media-replace-flow-on-success
branch
from
September 24, 2026 18:15
075beeb to
6a74ff6
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Update: Following testing on #83290,
@wordpress/upload-mediadoes indeed callonChange?.([attachment])with the server attachment upon completion, and block attributes (id,href) update properly in state.However, this PR addresses the visual bug in
core/file(#83290) where replacing an embedded PDF in Chrome / Chromium browsers leaves the editor's embedded preview canvas frozen on the previous document.This PR fixes a bug (#83290) where replacing an existing media item in any block utilizingMediaReplaceFlow(such ascore/file,core/image,core/cover,core/audio,core/video) fails to update the block when Client-Side Media Processing is active in WordPress 7.1+.Why?
Actual Root Cause:
In
packages/block-library/src/file/edit.jsx, PDF files with inline previews enabled are rendered using an HTML<object>tag:When a user replaces an existing PDF via Replace → Upload or Replace → Open Media Library:
hrefattribute updates to the new attachment URL.<object>lacks a Reactkeyprop, React performs in-place reconciliation and updates the DOM attribute (element.setAttribute('data', href)).dataattribute on an existing<object>DOM node. It remains frozen displaying the previous PDF document.fileNametext link attribute also remain identical, making the block appear visually unchanged.With Client-Side Media Processing enabled (window.__clientSideMediaProcessing),getSettings().mediaUploaddelegates to@wordpress/upload-media:1. During processing,upload-mediafiresonChangewith a transientblob:URL representation ({ url: blobUrl }).2. Blocks receiving this transient URL (e.g.FileEdit,ImageEdit) recognize it viaisBlobURL()and return early after caching it in local transient state, waiting for the finalized server attachment before updating persistent block attributes (id,url/href,fileName).3. When the server-side upload completes,@wordpress/upload-mediainvokesonSuccess([attachment]).4. Previously,MediaReplaceFlowonly suppliedonFileChangeand omittedonSuccess. Consequently, the finalized attachment was dropped, the transient blob URL was revoked, and the block fell back to referencing the previous attachment.How?
Updated Fix:
Add
key={ href }to the<object>element inpackages/block-library/src/file/edit.jsx:When
hrefchanges, React unmounts the old<object>DOM node and mounts a new one, cleanly restarting the browser's PDF viewer instance with the new URL.Initial proposed approach in MediaReplaceFlow (superseded)Inpackages/block-editor/src/components/media-replace-flow/index.jsx, we supply anonSuccesscallback tomediaUploadthat mirrorsonFileChange:This ensures that:- For client-side media processing,selectMediais called with the finalized server attachment upon completion.- For legacy server-side media processing (@wordpress/media-utils), the existingonFileChangeworkflow continues to work seamlessly without regressions.Patch Diff
Unit Test Addition
Initial MediaReplaceFlow unit test (superseded)Add topackages/block-editor/src/components/media-replace-flow/test/index.js:Note: The fix adds a React
keyprop to the File block's preview<object>element to control DOM reconciliation for browser PDF viewer reload.Testing Instructions
core/file).