Skip to content

Extract media editor save hook#78225

Merged
ramonjd merged 1 commit into
WordPress:trunkfrom
ramonjd:update/media-editor-save-hook
May 14, 2026
Merged

Extract media editor save hook#78225
ramonjd merged 1 commit into
WordPress:trunkfrom
ramonjd:update/media-editor-save-hook

Conversation

@ramonjd
Copy link
Copy Markdown
Member

@ramonjd ramonjd commented May 13, 2026

What?

Part of:


  • Extracts the media editor save flow from MediaEditorContent into a dedicated useSaveMediaEditor hook.
  • Keeps crop modifier generation, metadata bundling, save notices, entity-store updates, and onSaved result handling together.
  • Leaves MediaEditorContent focused on editor layout, interaction state, discard behavior, and frame wiring.

Why?

This makes the modal save path easier to reason about independently from the UI shell, while preserving the current crop + metadata save behavior.

Testing

There should be no regressions.

Enable the media modal experiment.

Insert an Image block into a post.

Hit the crop icon in the Image block toolbar.

Crop an image and save it.

Crop an image, change the metadata and save it.

Change the metadata and save it.

@ramonjd ramonjd force-pushed the update/media-editor-save-hook branch from c32ba0a to e14ad97 Compare May 14, 2026 00:33
@ramonjd ramonjd self-assigned this May 14, 2026
@ramonjd ramonjd force-pushed the update/media-editor-save-hook branch from e14ad97 to 87c131d Compare May 14, 2026 00:56
@ramonjd ramonjd added [Feature] Media Anything that impacts the experience of managing media [Type] Experimental Experimental feature or API. labels May 14, 2026
@ramonjd ramonjd marked this pull request as ready for review May 14, 2026 01:02
@ramonjd ramonjd requested review from andrewserong and Copilot May 14, 2026 01:02
@github-actions
Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the media editor modal’s save flow by extracting the save logic out of MediaEditorContent into a dedicated useSaveMediaEditor hook, keeping save-related concerns (crop modifier generation, metadata bundling, entity-store updates, notices, and onSaved handling) together while simplifying the UI shell component.

Changes:

  • Added useSaveMediaEditor hook encapsulating the full save pipeline for cropped and non-cropped edits.
  • Updated MediaEditorContent to delegate saving and notices context to the new hook while keeping discard/interaction logic local.
  • Re-exported MediaEditorSaveResult type from the new hook module for continuity.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/media-editor/src/components/media-editor/use-save-media-editor.ts New hook implementing the media editor save flow (crop + metadata + entity updates + notices).
packages/media-editor/src/components/media-editor/index.tsx Removes inline save implementation and wires saving through useSaveMediaEditor and shared notices context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks like a good and clean refactor to me!

✅ Crops work and save as on trunk
✅ Metadata gets saved correctly alongside the crop
✅ Updating metadata separately from a crop works as on trunk

The only thing of interest I found from giving this a quick pass with Claude was that the refactor might make it easier to add tests for some of the save logic in follow-ups:

The extracted seam is testable in isolation now, and packages/media-editor/src/components/media-editor/test/ happens to be empty, so this would be a natural place to add
useSaveMediaEditor unit tests in a follow-up if useful (modifier branch vs. non-modifier branch, post-parent carry-over, error formatting).

LGTM! 🚀

@ramonjd ramonjd enabled auto-merge (squash) May 14, 2026 01:35
@ramonjd ramonjd merged commit 521e717 into WordPress:trunk May 14, 2026
89 of 97 checks passed
@github-actions github-actions Bot added this to the Gutenberg 23.3 milestone May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Media Anything that impacts the experience of managing media [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants