Skip to content

Image: Restore alt text and caption when undoing a media editor save - #82829

Draft
ramonjd wants to merge 1 commit into
trunkfrom
fix/image-media-editor-undo-metadata
Draft

ramonjd wants to merge 1 commit into
trunkfrom
fix/image-media-editor-undo-metadata

Conversation

@ramonjd

@ramonjd ramonjd commented Sep 14, 2026

Copy link
Copy Markdown
Member

Caution

I haven't tested/curated this PR yet. It's a placeholder mainly.

What?

Undoing a media editor save on the Image block now restores the block's alt text and caption, not just the image.

Why?

A save that creates a new attachment can sync that attachment's alt text and caption onto the block. The "Image edited." snackbar's Undo only passes back the previous attachment's id and URL, so the image reverted but the synced alt text and caption stayed. Restoring the original image (#81805) makes this more likely.

How?

useOpenImageMediaEditorModal keeps the alt text and caption a save overwrote, along with the attachment the block moved away from, and puts them back when the next update returns the block to that attachment. Opening the modal clears them, so a later save back to the same attachment isn't mistaken for an Undo.

Testing Instructions

  1. In a post, insert an Image block from the Media Library, using an image that has alt text.
  2. Open the media editor from the block toolbar.
  3. In the Details tab, change the alt text, crop the image, and save.
  4. Check that the block's alt text is the new value.
  5. Click Undo in the "Image edited." snackbar.
  6. Check that the block shows the original image and its original alt text.
  7. Repeat with the caption.

Before

Kapture.2026-09-14.at.17.22.39.mp4

After

Kapture.2026-09-14.at.17.24.30.mp4

A save that moves the block to a new attachment can sync that
attachment's alt text and caption onto the block. The snackbar's Undo
only reports the previous attachment's id and url, so it reverted the
image but left the synced metadata behind. Keep the values the sync
overwrote and put them back when the block returns to that attachment.
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: +28 B (0%)

Total Size: 8.1 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 364 kB +28 B (+0.01%)

67c6f34 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric fd3593e trunk % Change
timeToFirstByte 45.1 ms +10.86% -2.44% 48.1 ms +10.19% -3.43% -6.24%
largestContentfulPaint 74 ms +8.11% -2.7% 76 ms +10.53% -0% -2.63%
lcpMinusTtfb 28.55 ms +12.26% -4.55% 29.4 ms +7.48% -4.08% -2.89%
wpBeforeTemplate 22.4 ms +17.72% -1.61% 23.54 ms +10.41% -1.87% -4.84%
wpTemplate 19.13 ms +3.92% -3.55% 20.64 ms +5.91% -3.54% -7.32%
wpTotal 41.99 ms +10.91% -3.07% 44.83 ms +9.15% -3.79% -6.34%
wpMemoryUsage 7.53 MB +0% -0% 7.49 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric fd3593e trunk % Change
timeToFirstByte 37.05 ms +6.88% -3.51% 38.65 ms +9.31% -2.59% -4.14%
largestContentfulPaint 82 ms +2.44% -2.44% 84 ms +4.76% -0% -2.38%
lcpMinusTtfb 44.5 ms +2.58% -1.91% 45.6 ms +1.64% -3.18% -2.41%
wpBeforeTemplate 19.81 ms +2.07% -2.02% 20.19 ms +5.5% -2.33% -1.88%
wpTemplate 14.53 ms +4.06% -3.58% 15.84 ms +7.58% -5.93% -8.27%
wpTotal 34.37 ms +7.3% -3.52% 35.96 ms +9.15% -3.39% -4.42%
wpMemoryUsage 6.15 MB +0% -0% 6.11 MB +0% -0% 0.59%
wpDbQueries 14 +0% -0% 14 +0% -0% 0%

media-processing

Metric fd3593e trunk % Change
mediaProcessingJpeg 322.98 ms +1.01% -1.34% 324.76 ms +0.95% -0.78% -0.55%
mediaProcessingAvif 4833.7 ms +0.48% -0.21% 4794.86 ms +0.03% -0.08% 0.81%
mediaProcessingJpegToAvif 3379.71 ms +0.37% -0.44% 3352.68 ms +0.13% -0.3% 0.81%

media-upload

Metric fd3593e trunk % Change
jpegUploadProcessing 1407.93 ms +2.16% -0.65% 1425.19 ms +0.59% -0.97% -1.21%
pngUploadProcessing 174.01 ms +1.42% -0.61% 208.16 ms +21.35% -8% -16.41%
largeJpegUploadProcessing 1406.21 ms +1.41% -0.52% 1392.38 ms +1.56% -0.57% 0.99%
multipleImageUploadProcessing 1475.31 ms +0.22% -0.53% 1502.99 ms +0.31% -1.95% -1.84%

post-editor

Metric fd3593e trunk % Change
serverResponse 506.42 ms +6.81% -7.8% 486.19 ms +4.5% -4.68% 4.16%
firstPaint 264.7 ms +11.55% -14.33% 224.67 ms +8.14% -23.05% 17.82%
domContentLoaded 1064.89 ms +2.66% -1.01% 1063.77 ms +2.91% -1.35% 0.11%
loaded 1066.21 ms +2.66% -1.01% 1065.09 ms +2.91% -1.36% 0.11%
firstContentfulPaint 432.19 ms +3.88% -1.43% 428.46 ms +2.44% -2.36% 0.87%
firstBlock 3296.89 ms +1.75% -0.86% 3266.84 ms +0.42% -0.48% 0.92%
type 20.08 ms +11.65% -7.72% 19.31 ms +4.19% -5.02% 3.99%
typeWithoutInspector 19.36 ms +16.68% -3.05% 19.62 ms +7.65% -3.62% -1.33%
typeWithTopToolbar 23.58 ms +17.26% -4.2% 23.75 ms +2.57% -1.94% -0.72%
typeContainer 9.01 ms +5.11% -7.77% 8.57 ms +7% -7.93% 5.13%
focus 68.29 ms +3.82% -13.82% 69.72 ms +7.13% -4.49% -2.05%
firstFocus 182.74 ms +0% -0% 187.28 ms +0% -0% -2.42%
selectAll 497.49 ms +6.65% -2.18% 513.21 ms +3.97% -0.97% -3.06%
listViewOpen 69.54 ms +9.22% -5.44% 68.19 ms +8.45% -8.32% 1.98%
inserterOpen 22.9 ms +7.82% -7.07% 22.74 ms +10.77% -9.32% 0.7%
inserterHover 3.26 ms +19.63% -5.21% 3.35 ms +12.84% -4.48% -2.69%
inserterSearch 7.53 ms +17.13% -5.31% 7.77 ms +21.11% -6.44% -3.09%
loadPatterns 631.38 ms +2.14% -2.66% 629.07 ms +8.64% -2.25% 0.37%
wpTotal 496.09 ms +6.95% -7.9% 476.42 ms +4.47% -4.85% 4.13%
wpMemoryUsage 13.06 MB +0% -0% 13.03 MB +0% -0% 0.25%
wpDbQueries 53.5 +0.93% -0.93% 54 +0% -0% -0.93%

site-editor

Metric fd3593e trunk % Change
serverResponse 391.52 ms +10.49% -4.27% 409.96 ms +2.78% -5.82% -4.5%
firstPaint 245.72 ms +17.98% -9.34% 236.27 ms +5.71% -18.31% 4%
domContentLoaded 1040.14 ms +1.47% -2.34% 1045.72 ms +1.47% -1.07% -0.53%
loaded 1041.24 ms +1.48% -2.35% 1046.88 ms +1.48% -1.08% -0.54%
firstContentfulPaint 417.75 ms +1.78% -1.32% 412.45 ms +1.91% -3.35% 1.29%
firstBlock 3714.71 ms +1.16% -1.17% 3718.24 ms +1.65% -1.41% -0.09%
type 20.33 ms +4.38% -3.64% 20.52 ms +2.58% -5.21% -0.93%
navigate 103.04 ms +7.14% -4.73% 110.73 ms +0.55% -0.36% -6.94%
loadPatterns 1454.31 ms +7.49% -11.06% 1381.69 ms +13.75% -7% 5.26%
loadPages 1097.14 ms +1.79% -2.35% 1055.12 ms +4.3% -1.4% 3.98%
wpTotal 381.26 ms +10.72% -4.3% 399.91 ms +2.94% -6.03% -4.66%
wpMemoryUsage 12.02 MB +0% -0% 11.98 MB +0% -0% 0.31%
wpDbQueries 43.5 +1.15% -1.15% 43.5 +1.15% -1.15% 0%

67c6f34 Run

🏁 Flaky tests

Show the failures

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-310-item-wrapper" class="dataviews-view-list__item" aria-labelledby="view-list-0-310-label" aria-describedby="view-list-0-310-description"></button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:146:49

67c6f34 Run

@ramonjd ramonjd self-assigned this Sep 14, 2026
@ramonjd ramonjd added the [Type] Bug An existing feature does not function as intended label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant