Skip to content

Gallery: Share figure and caption between static and dynamic modes - #86787

Merged
Mamaduka merged 1 commit into
trunkfrom
update/gallery-figure-classes
Nov 16, 2026
Merged

Mamaduka merged 1 commit into
trunkfrom
update/gallery-figure-classes

Conversation

@Mamaduka

Copy link
Copy Markdown
Member

What?

Follow up to #86768.

Static and dynamic galleries now both render through Gallery in gallery.jsx, which builds the <figure> classes and caption once. No user-visible change.

Why?

The <figure> classes (blocks-gallery-grid, align, columns-*, is-cropped, layout classes) and the caption were built twice, in gallery.jsx and in the dynamic branch of edit.jsx and GalleryDynamicView, so a change to one mode could miss the other. edit.jsx drops from 579 to 562 lines.

How?

Gallery takes the inner blocks or the dynamic preview as children, and the classes stay there rather than in useBlockProps so the empty-gallery placeholder doesn't get them. The isContentLocked prop is removed: block edit components haven't received it since #50643, so it was always undefined.

Testing Instructions

  1. Open a post or page.
  2. Insert a Gallery block with three images, set Columns to 2, turn off Crop images to fit, and set Align to Wide. The editor shows two uncropped columns at wide width.
  3. Click Add caption in the block toolbar and type a caption.
  4. Upload two images to the post, insert another Gallery block, and click Use attached images.
  5. In Settings, set Columns to 2 and turn off Crop images to fit. The preview shows two uncropped columns, and the caption is editable.

Testing Instructions for Keyboard

Same as above.

Use of AI Tools

Assisted by Claude.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mamaduka Mamaduka added [Type] Code Quality Issues or PRs that relate to code quality [Package] Block library /packages/block-library [Block] Gallery Affects the Gallery Block - used to display groups of images labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 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: Mamaduka <mamaduka@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.


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.

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric e031900 trunk % Change
timeToFirstByte 55.4 ms +9.75% -2.35% 60.5 ms +4.46% -3.88% -8.43%
largestContentfulPaint 86 ms +16.28% -2.33% 98 ms +6.12% -2.04% -12.24%
lcpMinusTtfb 30.9 ms +26.7% -5.34% 38.2 ms +4.58% -11.13% -19.11%
wpBeforeTemplate 29.57 ms +9.27% -2.84% 31.54 ms +6.59% -3.87% -6.25%
wpTemplate 22.2 ms +5.05% -3.38% 23.96 ms +6.64% -4.01% -7.35%
wpTotal 51.6 ms +9.96% -2.75% 56.25 ms +4.98% -3.79% -8.27%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric e031900 trunk % Change
timeToFirstByte 46.6 ms +6.65% -1.93% 50.95 ms +4.02% -3.83% -8.54%
largestContentfulPaint 84 ms +4.76% -4.76% 88 ms +6.82% -0% -4.55%
lcpMinusTtfb 35.3 ms +6.8% -2.83% 38.25 ms +9.41% -6.41% -7.71%
wpBeforeTemplate 26.34 ms +4.94% -1.06% 27.98 ms +11.9% -3.5% -5.86%
wpTemplate 17.08 ms +3.51% -3.86% 18.42 ms +4.72% -4.07% -7.27%
wpTotal 43.46 ms +6.56% -2.02% 46.4 ms +6.31% -1.87% -6.34%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric e031900 trunk % Change
mediaProcessingJpeg 405.9 ms +4.45% -0.73% 414.42 ms +1.32% -0.47% -2.06%
mediaProcessingAvif 6223.97 ms +0.45% -0.68% 6206.35 ms +0.22% -0.33% 0.28%
mediaProcessingJpegToAvif 4299.93 ms +0.68% -0.54% 4272.28 ms +0.33% -0.48% 0.65%

media-upload

Metric e031900 trunk % Change
jpegUploadProcessing 1998.86 ms +3.66% -20.38% 2003.2 ms +0.31% -20.19% -0.22%
pngUploadProcessing 294.91 ms +2.78% -4.25% 275.19 ms +4.61% -1.31% 7.17%
largeJpegUploadProcessing 2005.11 ms +0.62% -1% 1764.15 ms +12.55% -13.39% 13.66%
multipleImageUploadProcessing 2119.72 ms +0.59% -0.26% 2105.17 ms +0.73% -1.02% 0.69%

post-editor

Metric e031900 trunk % Change
serverResponse 343.84 ms +2.08% -3.57% 332.7 ms +4.74% -6.51% 3.35%
firstPaint 350.39 ms +9.68% -1.95% 341.58 ms +5.45% -2.61% 2.58%
domContentLoaded 655.23 ms +11.91% -1.87% 659.9 ms +2.11% -1.77% -0.71%
loaded 656.08 ms +11.91% -1.88% 660.86 ms +2.11% -1.78% -0.72%
firstContentfulPaint 375.28 ms +17.21% -2.7% 366.26 ms +4.44% -1.8% 2.46%
firstBlock 1716.1 ms +2.29% -1.29% 1708.95 ms +1.98% -1.44% 0.42%
type 14.75 ms +5.63% -11.8% 15.49 ms +8.26% -7.55% -4.78%
typeWithoutInspector 14.86 ms +9.08% -9.42% 15.89 ms +5.92% -11.83% -6.48%
typeWithTopToolbar 18.88 ms +9.64% -5.24% 19.92 ms +2.46% -5.87% -5.22%
typeContainer 7.1 ms +7.61% -6.48% 7.17 ms +4.46% -6.14% -0.98%
focus 99.23 ms +7.33% -1.97% 95.54 ms +7.48% -6.82% 3.86%
firstFocus 207.4 ms +0% -0% 203.95 ms +0% -0% 1.69%
selectAll 280.43 ms +2.07% -2.49% 277.13 ms +2.84% -1.28% 1.19%
undo 22.48 ms +6.36% -5.74% 25.39 ms +2.91% -7.09% -11.46%
listViewOpen 63.78 ms +10.52% -10.13% 59.67 ms +6.4% -7.41% 6.89%
inserterOpen 35.35 ms +3.2% -8.15% 35.25 ms +14.64% -5.73% 0.28%
inserterHover 9.47 ms +9.19% -4.12% 9.45 ms +12.28% -9.21% 0.21%
inserterSearch 7.39 ms +8.39% -10.42% 7.1 ms +13.94% -4.51% 4.08%
loadPatterns 527.89 ms +3.08% -2.36% 525.85 ms +1.9% -4.5% 0.39%
wpTotal 335.56 ms +1.83% -3.87% 324.41 ms +4.6% -6.64% 3.44%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric e031900 trunk % Change
serverResponse 388.88 ms +5.7% -6.42% 409.05 ms +0.42% -7.45% -4.93%
firstPaint 461.16 ms +5.08% -13.64% 427.28 ms +10.96% -5.95% 7.93%
domContentLoaded 825.73 ms +1.71% -1.95% 842 ms +1.39% -0.92% -1.93%
loaded 826.91 ms +1.7% -1.99% 843.14 ms +1.38% -0.91% -1.92%
firstContentfulPaint 471.51 ms +2.78% -3.66% 471.99 ms +0.59% -1.81% -0.1%
firstBlock 2457.88 ms +1.7% -0.95% 2529.93 ms +1.45% -1.1% -2.85%
type 18.96 ms +3.01% -7.38% 18.54 ms +4.48% -6.8% 2.27%
navigate 110.33 ms +6.45% -0.5% 118.86 ms +1.03% -4.16% -7.18%
loadPatterns 1337.43 ms +3.6% -13.39% 1418.36 ms +6.82% -5.62% -5.71%
loadPages 920.44 ms +1.69% -1.14% 923.4 ms +3.9% -0.79% -0.32%
wpTotal 378.28 ms +5.78% -6.63% 398.37 ms +0.42% -7.65% -5.04%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

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

Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
should apply a named font size using the font size buttons in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"large"} -->
+ <!-- wp:paragraph {"fontSize":"medium"} -->
- <p class="has-large-font-size">Paragraph to be made "large"</p>
+ <p class="has-medium-font-size">Paragraph to be made "large"</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:153:6
should reset a named font size using input field in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"small"} -->
+ <!-- wp:paragraph {"fontSize":"tiny"} -->
- <p class="has-small-font-size">Paragraph with font size reset using input field</p>
+ <p class="has-tiny-font-size">Paragraph with font size reset using input field</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:216:6
should reset a named font size using the tools panel menu in /test/e2e/specs/editor/various/font-size-picker.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:paragraph {"fontSize":"medium"} -->
+ <!-- wp:paragraph {"fontSize":"small"} -->
- <p class="has-medium-font-size">Paragraph with font size reset using tools panel menu</p>
+ <p class="has-small-font-size">Paragraph with font size reset using tools panel menu</p>
  <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/font-size-picker.spec.js:178:6
three users concurrently edit a large post with diverse blocks in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
TimeoutError: locator.waitFor: Timeout 17500ms exceeded.
Call log:
  - waiting for getByRole('button', { name: /Collaborators list/ }) to be visible

    at map (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts:193:7)
    at CollaborationUtils.waitForMutualDiscovery (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts:188:10)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:416:28

0134749 Run

@Mamaduka

Copy link
Copy Markdown
Member Author

@andrewserong, @ramonjd, I promise, I only have one refactoring PR left on the list 😄

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

Very cool, I didn't notice that the dynamic gallery could so easily re-use the static version's Gallery component. Nicely done!

Smoke tested adding and removing captions on the static and dynamic blocks, and all the different styling states for the dynamic variation (number of columns, wide/full layouts, cropping images, etc)

Looking good 🚀

@Mamaduka
Mamaduka merged commit 0b29aa8 into trunk Nov 16, 2026
127 of 129 checks passed
@Mamaduka
Mamaduka deleted the update/gallery-figure-classes branch November 16, 2026 07:39
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 16, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…ordPress#86787)

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Gallery Affects the Gallery Block - used to display groups of images [Package] Block library /packages/block-library [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