Skip to content

Media editor: Pass mediaType to frames instead of isImage - #87871

Merged
ramonjd merged 2 commits into
trunkfrom
update/media-editor-frame-media-type
Dec 3, 2026
Merged

ramonjd merged 2 commits into
trunkfrom
update/media-editor-frame-media-type

Conversation

@ramonjd

@ramonjd ramonjd commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

What?

Follow-up to #84664, from this review comment.

renderFrame and the frame context pass mediaType (image, video, audio or application) instead of isImage.

It is null until the media loads, where isImage was false.

The media editor route reads it for its narrow History bar.

Why?

isImage is narrow and superfluous. With the type, a frame can tell every media type apart. 👍🏻

Testing Instructions

  1. Insert an Image block, choose an image, and click "Edit image" in the block toolbar. Reset, Undo and Redo show, and the More menu has "Keyboard shortcuts".
  2. Enable the "Media Editor (Route)" experiment, head to the Media Library. Ppen an image in the media editor page, and narrow the window below the small breakpoint. The History bar shows under the canvas.
  3. Also in the Media Library, upload and edit a PDF. No history buttons show.
Screenshot 2026-12-03 at 5 00 44 pm Screenshot 2026-12-03 at 5 00 02 pm

`renderFrame` and the frame context now carry the media type, or `null`
until the media loads, so frames can tell every type apart. The route's
narrow History bar checks `mediaType === 'image'`.
@ramonjd ramonjd added [Feature] Media Anything that impacts the experience of managing media [Type] Code Quality Issues or PRs that relate to code quality labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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 <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +14 B (0%)

Total Size: 8.73 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 575 kB +14 B (0%)

e7230ef Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 7a25368 trunk % Change
timeToFirstByte 56.9 ms +7.64% -3.78% 56.65 ms +7.77% -4.5% 0.44%
largestContentfulPaint 92 ms +10.87% -4.35% 88 ms +6.82% -4.55% 4.55%
lcpMinusTtfb 36.95 ms +6.63% -12.31% 32.3 ms +11.92% -19.35% 14.4%
wpBeforeTemplate 30.37 ms +10.57% -3.19% 30.03 ms +9.06% -2.53% 1.13%
wpTemplate 22.44 ms +3.92% -2.63% 22.08 ms +6.66% -3.85% 1.63%
wpTotal 53.09 ms +8.14% -3.71% 52.86 ms +7.66% -4.41% 0.44%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 7a25368 trunk % Change
timeToFirstByte 46.25 ms +6.27% -1.3% 46.1 ms +10.63% -0.87% 0.33%
largestContentfulPaint 80 ms +7.5% -0% 80 ms +7.5% -0% 0%
lcpMinusTtfb 34.85 ms +5.02% -2.3% 34.3 ms +0.87% -1.02% 1.6%
wpBeforeTemplate 27.27 ms +3.34% -1.69% 26.99 ms +7.15% -1.07% 1.04%
wpTemplate 15.9 ms +7.61% -1.76% 16.06 ms +4.23% -1.74% -1%
wpTotal 43.29 ms +6.35% -1.32% 43.11 ms +10.25% -1.18% 0.42%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 7a25368 trunk % Change
mediaProcessingJpeg 401.1 ms +0.17% -0.97% 396.04 ms +0.63% -0.6% 1.28%
mediaProcessingAvif 6126.33 ms +0.72% -0.29% 6076.76 ms +0.43% -0.07% 0.82%
mediaProcessingJpegToAvif 4222.21 ms +0.15% -0.22% 4196.17 ms +0.16% -0.14% 0.62%

media-upload

Metric 7a25368 trunk % Change
jpegUploadProcessing 1987.56 ms +1.06% -22.19% 1534.46 ms +29.15% -2.03% 29.53%
pngUploadProcessing 267.92 ms +5.82% -4.75% 269.36 ms +1.38% -4.44% -0.53%
largeJpegUploadProcessing 1951.83 ms +1.37% -22.01% 1511.55 ms +28.77% -1.53% 29.13%
multipleImageUploadProcessing 2107.23 ms +1.35% -1.02% 2069.23 ms +1% -18.29% 1.84%

post-editor

Metric 7a25368 trunk % Change
serverResponse 310.14 ms +1.8% -1.92% 294.6 ms +1.59% -1.54% 5.27%
firstPaint 342.66 ms +11.35% -8.82% 321.66 ms +5.45% -15.45% 6.53%
domContentLoaded 636.92 ms +2.95% -4.72% 594.57 ms +3.94% -2.28% 7.12%
loaded 638.29 ms +2.93% -4.76% 595.82 ms +3.97% -2.31% 7.13%
firstContentfulPaint 345.32 ms +10.49% -1.32% 330.53 ms +4.21% -2.84% 4.47%
firstBlock 1667.83 ms +3.05% -1.38% 1601.68 ms +1.5% -1.38% 4.13%
type 16 ms +1.94% -14.31% 15.83 ms +3.66% -10.87% 1.07%
typeWithoutInspector 15.37 ms +9.76% -10.87% 15.47 ms +5.11% -15.13% -0.65%
typeWithTopToolbar 20.94 ms +4.82% -9.46% 19.55 ms +4.09% -8.54% 7.11%
typeContainer 7.33 ms +3.41% -5.32% 7.16 ms +4.89% -7.82% 2.37%
focus 82.74 ms +4.05% -3.41% 78.98 ms +8.14% -3.76% 4.76%
firstFocus 211.14 ms +0% -0% 187.79 ms +0% -0% 12.43%
selectAll 256.18 ms +2.93% -0.54% 278.64 ms +0.26% -3.95% -8.06%
undo 23.46 ms +4.26% -1.83% 24.6 ms +5.69% -4.88% -4.63%
listViewOpen 29.81 ms +7.31% -6.17% 28.69 ms +9.13% -3.49% 3.9%
inserterOpen 30.49 ms +17.22% -5.61% 33.07 ms +3.33% -6.38% -7.8%
inserterHover 9.57 ms +7.42% -5.33% 9.83 ms +8.55% -4.68% -2.64%
inserterSearch 7.97 ms +2.51% -7.28% 8.22 ms +10.58% -4.14% -3.04%
loadPatterns 503.16 ms +1.5% -0.9% 519.71 ms +5.37% -3.12% -3.18%
wpTotal 302.11 ms +1.79% -1.98% 287.11 ms +1.67% -1.62% 5.22%
wpMemoryUsage 14.80 MB +0% -0% 14.76 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 7a25368 trunk % Change
serverResponse 309.77 ms +5.5% -5.96% 326.29 ms +0.54% -0.6% -5.06%
firstPaint 363.91 ms +9.76% -13.03% 332.39 ms +9.21% -5.01% 9.48%
domContentLoaded 679.57 ms +3.43% -1.12% 694.13 ms +1.13% -1.35% -2.1%
loaded 680.88 ms +3.42% -1.14% 695.41 ms +1.14% -1.34% -2.09%
firstContentfulPaint 395.43 ms +4.01% -4.32% 377.55 ms +4.12% -2.65% 4.74%
firstBlock 2106.24 ms +1.18% -0.99% 2117.32 ms +1.22% -0.27% -0.52%
type 14.85 ms +5.59% -8.15% 15.46 ms +13.13% -5.76% -3.95%
navigate 96.61 ms +6.29% -6.33% 97.42 ms +9.2% -3.46% -0.83%
loadPatterns 1315.51 ms +8.15% -9.04% 1257.44 ms +4.91% -3.08% 4.62%
loadPages 963.51 ms +4.7% -2.7% 1003.45 ms +4.61% -0.97% -3.98%
wpTotal 301.26 ms +5.66% -6.1% 317.83 ms +0.55% -0.61% -5.21%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

e7230ef Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Navigates the items list via UP/DOWN arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByLabel('Page Two')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByLabel('Page Two') with timeout 5000ms
  - waiting for getByLabel('Page Two')
    14 × locator resolved to <button type="button" tabindex="-1" aria-pressed="false" id="view-list-0-194-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-194-label" aria-describedby="view-list-0-194-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:146:49
should undo without broken temporary state in /test/e2e/specs/editor/blocks/image.spec.js, passed after 2 failed attempts.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":22,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8891/wp-content/uploads/2026/12/e509fbd1-f88d-4d6e-ab72-80fcd2909178.png" alt="" class="wp-image-22"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":24,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8891/wp-content/uploads/2026/12/fd5ae785-d85a-4c1d-9215-861c56a695b3.png" alt="" class="wp-image-24"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49

e7230ef Run

@ramonjd ramonjd self-assigned this Dec 3, 2026
@ramonjd
ramonjd requested a balanced review from Copilot December 3, 2026 05:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the mediaType frame-prop update.

No open issues 🎉

What changed in this PR

Updates media editor frames to receive mediaType instead of isImage, allowing frames to distinguish media types.

Changes:

  • Passes mediaType through frame props and context, using null while loading.
  • Updates image-only controls and the modal test mock to use the new property.
File Description
routes/​media-editor/​stage.tsx Uses mediaType to show the narrow image History bar.
packages/​media-editor/​src/​components/​media-editor/​index.tsx Replaces frame isImage with mediaType and updates conditional controls.
packages/​media-editor/​src/​components/​media-editor-modal/​test/​index.browser.test.tsx Updates mocked frame props to supply mediaType.

Review effort: Balanced

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code change looks good, and it's smoke testing well for me.

Thanks for the follow-ups! 🚀

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

Comment on lines +134 to +137
* The type of the media being edited, or `null` until it loads. The
* history and transform clusters render nothing unless it is `image`, so a
* frame uses this to decide whether the container it would put them in is
* worth rendering at all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"Clusters" reads like a breakfast cereal. I'm going to do a doc's pass on all this next.

Suggested change
* The type of the media being edited, or `null` until it loads. The
* history and transform clusters render nothing unless it is `image`, so a
* frame uses this to decide whether the container it would put them in is
* worth rendering at all.
* The type of the media being edited, or `null` until it loads.
* `MediaEditor.HistoryActions` (Reset, Undo, Redo) renders nothing unless
* it is `image`, so a frame can skip the container it would put them in.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually, just /** The type of the media being edited, or null until it loads. */ is better.

@ramonjd

ramonjd commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Thanks for the quick reviews, folks!

@ramonjd
ramonjd enabled auto-merge (squash) December 3, 2026 06:10
@ramonjd
ramonjd merged commit fa5f087 into trunk Dec 3, 2026
81 checks passed
@ramonjd
ramonjd deleted the update/media-editor-frame-media-type branch December 3, 2026 06:29
@github-actions github-actions Bot added this to the Gutenberg 24.7 milestone Dec 3, 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] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants