Media Editor Modal: Fix empty author and attached to fields#78189
Conversation
|
Size Change: +50 B (0%) Total Size: 7.93 MB 📦 View Changed
ℹ️ View Unchanged
|
|
I can see the attached to value now! Do you think it's out of scope here in this PR to make the field more dynamic? E.g., when the post is published, the new attachment id is picked up. Or when I swap attached to parents and save, using the newly-selected post id. Kapture.2026-05-13.at.10.29.32.mp4 |
|
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. |
Not at all! I had it on my list to dig into today (or this week if it's more complex than I think), so happy to chip away at it in this PR. Thanks for testing! |
Ah great, just wanted to know whether we should ship this as is. I'll approve if it's gonna be a follow up. |
Cheers! I'll have a play today and make a call later on whether to merge and open a follow-up or if we're better off rolling into this one 🙂 |
…nd use 'no title' fallback in the attached_to field for consistency with the core media library
…r has not customised anything
|
Update: I've pushed some changes to make it feel a bit more dynamic. Let me know if I missed anything! Here are the changes:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes cases where the experimental Media Editor Modal shows empty Author and Attached to fields by ensuring the attachment entity is fetched with the required _embedded data, and it aligns “Attached to” display behavior with the core Media Library when a parent post has no title.
Changes:
- Trigger an
_embedd attachment fetch inMediaEditorContentand invalidate its cached resolution on mount /idchange so embedded author/parent data stays fresh. - Update the “Attached to” view to display
(no title)when the embedded parent post exists but has an empty title. - Add unit tests for the “Attached to” view behavior (title rendering,
(no title),(Unattached), and stale embedded mismatch).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/media-fields/src/attached_to/view.tsx |
Adjusts “Attached to” display fallback to (no title) when the embedded parent has an empty title. |
packages/media-fields/src/attached_to/test/view.test.tsx |
Adds test coverage for key “Attached to” rendering scenarios and edge cases. |
packages/media-editor/src/components/media-editor/index.tsx |
Ensures attachments are fetched with _embed data, invalidates stale resolutions on open, and carries post across /edit crop requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Kapture.2026-05-13.at.13.25.02.mp4
|
|
Thanks for re-testing! 🙇 |
What?
Part of:
Fix the sometimes empty nature of the author and attached to fields in the experimental Media Editor Modal.
Why?
Sometimes these fields aren't populated because the entity hasn't resolved the embedded fields. In order to use these properly, we need to make sure that they are fetched and stored in the store. The main way you encounter this is if you drag and drop an image from your desktop onto a post (a published post is a better way to test this, as it'll have a title that gets shown in the Attached To field).
In such a case, a new upload has occurred but when we click the crop button in the block toolbar on the image block, the loaded entity doesn't have the embedded data it needs, and so the username and attached to fields appear blank, when they are not.
How?
MediaEditorContent, fill the data store by triggering an_embedfetch with the embedded author and attached to fieldsgetEditedEntityRecord. While that technically works, that method's signature doesn't include aqueryparam, and it's only an artifact of its resolver that it's possible to pass a query object to it. The approach in this PR seemed a bit more "correct" without going into core-data and updating the selector itself. Let me know if that direction seems better and I can update this PR (or close it out and open a fresh PR)Included tweaks to polish the behaviour
(no title)for consistency with the core media library. I've included a few tests to make sure this is covered.Note: things to deal with separately (as it's possibly more to do with the field itself):
Testing Instructions
adminif you're the admin user)Screenshots or screencast
Before
Note the empty Author and Attached to fields
After
Use of AI Tools
Claude Code