Skip to content

Media editor: Validate attachment titles when editing - #86219

Draft
ramonjd wants to merge 3 commits into
trunkfrom
fix/media-title-empty
Draft

ramonjd wants to merge 3 commits into
trunkfrom
fix/media-title-empty

Conversation

@ramonjd

@ramonjd ramonjd commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What?

Let users clear and replace attachment titles while editing, and require a title containing at least one non-space character before saving in the media editor.

Why?

The attachment title field uses a display helper that substitutes (no title) for an empty value, so the controlled input immediately puts that text back when the user clears it. Returning the actual editable value fixes that behavior, while explicit validation prevents saving an empty or whitespace-only title.

2026-11-03.11.16.40.mp4

How?

Read the raw attachment title with the existing raw-content helper. Add the field’s required rule and a custom validator for whitespace-only values. Use DataViews’ existing useFormValidity hook for editable fields in the media editor, pass the resulting feedback to MediaForm, and disable and guard Save while those fields are invalid. Read-only metadata is excluded from validation because users cannot correct it in this form.

2026-11-03.11.54.07.mp4

Testing Instructions

  1. Insert an Image block, add an image and open the media editor modal.
  2. Open details and clear the title field. Confirm it stays empty, Save is disabled, and moving focus away shows the required-field error.
  3. Enter only spaces and move focus away. Confirm the inline message asks for a title with at least one non-space character and Save stays disabled.
  4. Enter a valid replacement title. Confirm the error clears and Save becomes available.
  5. Save and reopen the attachment. Confirm the title was retained.

Validation

  • Existing attachment, media-form, form-validity, and restore-original browser suites pass (128 tests).
  • Lint, core-fields and media-editor type checks, changelog validation, published dependency checks, and the full production build pass.
  • Browser verification covers empty and whitespace-only title errors and recovery to a valid title.
  • No new test cases were added; the existing attachment title expectation was updated.

Use of AI Tools

Codex prepared the code changes, ran validation, and wrote this pull request description.

@github-actions github-actions Bot added the [Package] Fields /packages/fields label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 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>

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: +160 B (0%)

Total Size: 8.58 MB

📦 View Changed
Filename Size Change
build/modules/core-fields/attachment.min.js 39.4 kB +70 B (+0.18%)
build/scripts/editor/index.min.js 559 kB +90 B (+0.02%)

444e871 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 41effee trunk % Change
timeToFirstByte 34 ms +16.03% -3.38% 34.5 ms +14.78% -4.49% -1.45%
largestContentfulPaint 58 ms +13.79% -3.45% 62 ms +6.45% -9.68% -6.45%
lcpMinusTtfb 23.95 ms +15.66% -5.43% 24.5 ms +12.24% -6.73% -2.24%
wpBeforeTemplate 17.85 ms +20.56% -2.3% 17.81 ms +29.14% -2.41% 0.22%
wpTemplate 13.1 ms +5.34% -3.44% 13.28 ms +6.4% -6.55% -1.36%
wpTotal 30.95 ms +16.32% -3% 31.66 ms +14.94% -5.18% -2.24%
wpMemoryUsage 7.71 MB +0% -0% 7.67 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 41effee trunk % Change
timeToFirstByte 29 ms +5.86% -2.93% 28.5 ms +9.12% -4.39% 1.75%
largestContentfulPaint 66 ms +3.03% -3.03% 64 ms +6.25% -0% 3.13%
lcpMinusTtfb 36.85 ms +1.9% -3.12% 36.05 ms +2.64% -6.8% 2.22%
wpBeforeTemplate 16.26 ms +6.83% -3.57% 15.57 ms +15.29% -2.06% 4.43%
wpTemplate 10.18 ms +3.54% -5.99% 9.84 ms +13.82% -4.78% 3.46%
wpTotal 26.38 ms +6.71% -3.56% 25.97 ms +9.78% -4.12% 1.58%
wpMemoryUsage 6.40 MB +0% -0% 6.36 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 41effee trunk % Change
mediaProcessingJpeg 229.59 ms +3.78% -3.01% 222.03 ms +0.44% -4.8% 3.4%
mediaProcessingAvif 3666.87 ms +0.36% -1.83% 3563.1 ms +1.05% -0.64% 2.91%
mediaProcessingJpegToAvif 2544.57 ms +1.3% -0.45% 2499.68 ms +1.09% -0.2% 1.8%

media-upload

Metric 41effee trunk % Change
jpegUploadProcessing 1405.75 ms +0.75% -0.68% 1390.73 ms +0.9% -0.37% 1.08%
pngUploadProcessing 176.53 ms +5.53% -5.19% 176.92 ms +2.47% -3.69% -0.22%
largeJpegUploadProcessing 1415.93 ms +0.34% -0.87% 1401.91 ms +0.42% -0.57% 1%
multipleImageUploadProcessing 1461.53 ms +0.78% -0.65% 1440.02 ms +1% -0.56% 1.49%

post-editor

Metric 41effee trunk % Change
serverResponse 340.98 ms +1.86% -3.94% 293.62 ms +15.55% -2.76% 16.13%
firstPaint 310.58 ms +33.45% -26.66% 302.48 ms +29.58% -25.03% 2.68%
domContentLoaded 697.43 ms +4.44% -4.34% 679.22 ms +1.99% -1.91% 2.68%
loaded 698.36 ms +4.41% -4.35% 680.13 ms +1.99% -1.9% 2.68%
firstContentfulPaint 413.66 ms +6.44% -4.3% 396.33 ms +2.58% -1.26% 4.37%
firstBlock 1779.44 ms +2.16% -2.97% 1729.31 ms +1.3% -1.46% 2.9%
type 15.64 ms +7.35% -7.86% 15.4 ms +8.44% -2.79% 1.56%
typeWithoutInspector 15.15 ms +7.92% -7% 15.65 ms +3.13% -8.95% -3.19%
typeWithTopToolbar 20.92 ms +9.23% -4.25% 19.3 ms +7.67% -3.63% 8.39%
typeContainer 7.33 ms +11.73% -8.46% 6.92 ms +4.19% -2.75% 5.92%
focus 92.72 ms +6.27% -3.35% 92.56 ms +5.48% -3.1% 0.17%
firstFocus 198.47 ms +0% -0% 200.67 ms +0% -0% -1.1%
selectAll 317.66 ms +2.51% -1.47% 319.91 ms +0.57% -0.03% -0.7%
undo 24.74 ms +6.99% -2.1% 25.45 ms +10.49% -5.03% -2.79%
listViewOpen 64.13 ms +9.82% -4.16% 63.45 ms +4.96% -14.01% 1.07%
inserterOpen 34.04 ms +1.91% -5.64% 33.23 ms +4.78% -8.13% 2.44%
inserterHover 10.08 ms +3.97% -8.04% 9.58 ms +4.28% -5.85% 5.22%
inserterSearch 7.34 ms +5.86% -5.45% 7.18 ms +20.33% -2.65% 2.23%
loadPatterns 512.54 ms +2.92% -3.27% 527.17 ms +6.58% -4.96% -2.78%
wpTotal 332.21 ms +1.56% -3.99% 284.97 ms +15.64% -2.85% 16.58%
wpMemoryUsage 14.75 MB +0% -0% 14.72 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 41effee trunk % Change
serverResponse 470.23 ms +1.63% -6.27% 488.77 ms +1.39% -7.84% -3.79%
firstPaint 375.48 ms +3.43% -6.41% 345.43 ms +47.04% -17.28% 8.7%
domContentLoaded 879.8 ms +4.61% -1.7% 895.49 ms +2.67% -0.89% -1.75%
loaded 881 ms +4.57% -1.73% 896.47 ms +2.68% -0.88% -1.73%
firstContentfulPaint 506.9 ms +3.49% -2.7% 511.66 ms +3.97% -2.14% -0.93%
firstBlock 2586.96 ms +2.65% -2.47% 2627.08 ms +0.63% -0.86% -1.53%
type 18.13 ms +12.74% -4.36% 17.53 ms +9.93% -7.59% 3.42%
navigate 126.64 ms +6.18% -5.35% 117.27 ms +9.47% -4.31% 7.99%
loadPatterns 1446.43 ms +5.28% -5.4% 1392.08 ms +3.14% -6.66% 3.9%
loadPages 1015.84 ms +2.64% -4.67% 1026.56 ms +1.58% -5.09% -1.04%
wpTotal 460.82 ms +1.55% -6.42% 479.32 ms +1.36% -8.02% -3.86%
wpMemoryUsage 12.77 MB +0% -0% 12.73 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

444e871 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.

should place the caret at the click position when clicking a block that is not selected in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

@@ -1,9 +1,9 @@
  Array [
    Object {
      "attributes": Object {
-       "content": "First!",
+       "content": "First",
      },
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:952:41
should select by dragging into nested block in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 0

  Array [
    1,
-   2,
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:569:5

444e871 Run

@ramonjd ramonjd changed the title Media editor: Allow attachment titles to be cleared Media editor: Validate attachment titles when editing Nov 3, 2026
@ramonjd
ramonjd marked this pull request as draft November 3, 2026 00:47
@ramonjd ramonjd self-assigned this Nov 3, 2026
@ramonjd ramonjd added the [Type] Enhancement A suggestion for improvement. label Nov 3, 2026
@ramonjd
ramonjd requested review from andrewserong and oandregal and removed request for andrewserong November 3, 2026 00:57
@ramonjd

ramonjd commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Not sure if this the right way to go about this. I think the current state of things is confusing for users, who should be able to clear a field.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Fields /packages/fields [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant