Skip to content

Media: Return 0 from the edit root lookup when there is no edit root - #84096

Merged
ramonjd merged 1 commit into
trunkfrom
backport/changes-from-wp-13303
Oct 6, 2026
Merged

ramonjd merged 1 commit into
trunkfrom
backport/changes-from-wp-13303

Conversation

@ramonjd

@ramonjd ramonjd commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

What?

Follow-up to #81803. Backports the changes from the review of WordPress/wordpress-develop#13303 (fecd8bd, 6c95f24). Props to @peterwilsoncc for the suggestions.

Why?

gutenberg_get_edit_root_attachment_id() should match core's wp_get_edit_root_attachment_id(), which now returns 0 when there is no edit root instead of the ID passed in.

How?

  • The lookup returns 0 for uploads and for attachments recorded as their own edit root.
  • The /edit hook falls back to the source attachment's ID when it has no edit root of its own.
  • The REST field and the wp:edit-root link check for 0 directly.
  • Tests with more than one assertion now have failure messages.

No change to the REST edit_root value: it was already 0 when there is no edit root.

Testing Instructions

  1. Upload an image, insert it in an Image block, crop it and apply.
  2. In the browser console, run await wp.apiFetch( { path: '/wp/v2/media/<new id>?context=edit' } ). edit_root is the original upload's ID and _links has wp:edit-root.
  3. Crop the cropped image again. The newest copy's edit_root is still the original upload's ID.
  4. Fetch the original upload the same way. edit_root is 0 and there is no wp:edit-root link.

Cropped image:

Screenshot 2026-10-06 at 2 38 09 pm

Original (root) image:

Screenshot 2026-10-06 at 2 39 12 pm

Backports the review changes from WordPress/wordpress-develop#13303:
the lookup returns 0 for uploads and for attachments recorded as their
own edit root, and multi-assertion tests carry failure messages.
@ramonjd
ramonjd requested a review from spacedmonkey as a code owner October 6, 2026 03:34
@ramonjd ramonjd added [Feature] Media Anything that impacts the experience of managing media [Type] Code Quality Issues or PRs that relate to code quality Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 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>

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

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

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric b684f3c trunk % Change
timeToFirstByte 43.4 ms +3.34% -2.07% 44.15 ms +13.14% -2.49% -1.7%
largestContentfulPaint 72 ms +8.33% -2.78% 74 ms +8.11% -2.7% -2.7%
lcpMinusTtfb 28.75 ms +14.96% -6.61% 28.3 ms +7.24% -7.24% 1.59%
wpBeforeTemplate 20.6 ms +7.43% -1.65% 20.82 ms +19.02% -1.83% -1.06%
wpTemplate 19.29 ms +3.27% -2.23% 19.48 ms +4.26% -3.18% -0.98%
wpTotal 40.03 ms +4.3% -1.87% 40.93 ms +12.22% -2.71% -2.2%
wpMemoryUsage 7.63 MB +0% -0% 7.60 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric b684f3c trunk % Change
timeToFirstByte 31.8 ms +7.86% -1.42% 35.7 ms +3.78% -3.22% -10.92%
largestContentfulPaint 72 ms +5.56% -5.56% 80 ms +2.5% -5% -10%
lcpMinusTtfb 40.55 ms +4.44% -9.25% 43.4 ms +6.34% -6.8% -6.57%
wpBeforeTemplate 18.27 ms +6.73% -1.86% 18.4 ms +1.85% -2.12% -0.71%
wpTemplate 10.97 ms +3.74% -2.37% 14.18 ms +4.37% -2.61% -22.64%
wpTotal 29.31 ms +7.68% -2.05% 32.94 ms +3.83% -3.22% -11.02%
wpMemoryUsage 6.12 MB +0% -0% 6.21 MB +0% -0% -1.57%
wpDbQueries 10 +0% -0% 14 +0% -0% -28.57%

media-processing

Metric b684f3c trunk % Change
mediaProcessingJpeg 334.7 ms +0.66% -1.9% 330.91 ms +1.75% -0.3% 1.15%
mediaProcessingAvif 4897.91 ms +0.12% -0.1% 4865.43 ms +0.3% -0.15% 0.67%
mediaProcessingJpegToAvif 3346.89 ms +0.4% -0.2% 3325.56 ms +0.1% -0.25% 0.64%

media-upload

Metric b684f3c trunk % Change
jpegUploadProcessing 1413.3 ms +1.27% -1.95% 1395.37 ms +1.27% -0.78% 1.28%
pngUploadProcessing 188.56 ms +2.57% -3.16% 189.6 ms +3.2% -4.21% -0.55%
largeJpegUploadProcessing 1389.12 ms +0.44% -0.37% 1388.37 ms +0.48% -0.32% 0.05%
multipleImageUploadProcessing 1474.76 ms +0.09% -0.37% 1479.11 ms +2.36% -1.04% -0.29%

post-editor

Metric b684f3c trunk % Change
serverResponse 247.73 ms +1.42% -3.16% 249.96 ms +4.11% -8.99% -0.89%
firstPaint 177.2 ms +35.54% -22.9% 136.19 ms +16.74% -12.31% 30.11%
domContentLoaded 630.35 ms +3.06% -3.36% 633.61 ms +2.8% -2.04% -0.51%
loaded 631.37 ms +3.05% -3.38% 634.69 ms +2.77% -2.08% -0.52%
firstContentfulPaint 284.17 ms +4.49% -5.33% 275.82 ms +5.24% -4.28% 3.03%
firstBlock 1850.3 ms +2.61% -1.43% 1840.6 ms +1.16% -1.19% 0.53%
type 12.74 ms +2.59% -3.61% 12.55 ms +3.27% -3.43% 1.51%
typeWithoutInspector 11.9 ms +0.84% -4.03% 11.91 ms +2.1% -3.61% -0.08%
typeWithTopToolbar 14.91 ms +3.49% -5.3% 14.47 ms +1.17% -4.15% 3.04%
typeContainer 6.21 ms +11.76% -12.72% 5.09 ms +7.86% -1.38% 22%
focus 43.27 ms +6.89% -7.12% 40.58 ms +12% -4.56% 6.63%
firstFocus 114.68 ms +0% -0% 117.42 ms +0% -0% -2.33%
selectAll 282.81 ms +4.44% -2.4% 288.53 ms +0.09% -5.18% -1.98%
listViewOpen 32.9 ms +17.33% -4.71% 32.99 ms +9.09% -14.22% -0.27%
inserterOpen 15.72 ms +6.81% -6.93% 15.61 ms +13.97% -7.62% 0.7%
inserterHover 1.46 ms +11.64% -9.59% 1.54 ms +10.39% -16.88% -5.19%
inserterSearch 5.82 ms +4.12% -5.33% 5.95 ms +5.21% -6.05% -2.18%
loadPatterns 420.54 ms +13.74% -6.63% 395.85 ms +2.83% -2.16% 6.24%
wpTotal 241.18 ms +1.46% -3.42% 243.3 ms +4.18% -9.29% -0.87%
wpMemoryUsage 13.18 MB +0% -0% 13.15 MB +0% -0% 0.28%
wpDbQueries 54 +0% -0% 54 +0% -0% 0%

site-editor

Metric b684f3c trunk % Change
serverResponse 259.6 ms +4.63% -6.01% 274.36 ms +2.64% -7.15% -5.38%
firstPaint 149.59 ms +36.18% -5.61% 175.97 ms +19.02% -11.2% -14.99%
domContentLoaded 761.36 ms +1.82% -1.69% 802.52 ms +0.92% -4.35% -5.13%
loaded 762.46 ms +1.82% -1.71% 803.6 ms +0.92% -4.34% -5.12%
firstContentfulPaint 324.57 ms +1.8% -1.56% 342.71 ms +2.35% -2.69% -5.29%
firstBlock 2637.94 ms +1.67% -1.15% 2826.41 ms +1.12% -0.82% -6.67%
type 14.46 ms +9.82% -5.67% 15.17 ms +14.57% -1.78% -4.68%
navigate 96.98 ms +4.23% -4.55% 79.96 ms +7.37% -3.48% 21.29%
loadPatterns 912.46 ms +1.46% -3.77% 949.95 ms +3.8% -8.45% -3.95%
loadPages 987.54 ms +5.54% -1.19% 978.9 ms +5.72% -2.06% 0.88%
wpTotal 252.98 ms +4.81% -6.21% 267.49 ms +2.69% -7.28% -5.42%
wpMemoryUsage 12.15 MB +0% -0% 12.13 MB +0% -0% 0.13%
wpDbQueries 44 +0% -2.27% 44 +0% -2.27% 0%

14c4934 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.

sort patterns (Site Editor v2) in /test/e2e/specs/site-editor/patterns.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → POST http://localhost:8889/wp-json/wp/v2/blocks
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.18 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: 4cd672b371
    - content-type: application/json
    - content-length: 137
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1791430798%7Cnpo2h7mE3R4SWqwd5MjGKHaGdl0R85WzTQfRHqxel1y%7C9e4b6f57e163a4da960e252fbf313cff9ce7c71bc5414576b65642b69c801f82; wp-settings-time-1=1791258300

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:112:39)
    at RequestUtils.createRecord (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/records.ts:20:14)
    at RequestUtils.createBlock (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/blocks.ts:54:14)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/patterns.spec.js:247:17

14c4934 Run

@ramonjd ramonjd self-assigned this Oct 6, 2026

@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.

Nice idea moving the logic to get_edit_root_attachment_id rather than at the field and link level, this feels tidier 👍

Smoke-tested that this is still working well for a non cropped image (edit root is 0) and a first crop and a crop of a crop both return the edit root of the original attachment.

LGTM! 🚀

@ramonjd
ramonjd enabled auto-merge (squash) October 6, 2026 03:54
@ramonjd
ramonjd merged commit 04edcbd into trunk Oct 6, 2026
117 checks passed
@ramonjd
ramonjd deleted the backport/changes-from-wp-13303 branch October 6, 2026 04:01
@github-actions github-actions Bot added this to the Gutenberg 24.2 milestone Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core [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.

2 participants