Skip to content

Add layout and block spacing support to Latest Posts block#77989

Open
tellthemachines wants to merge 6 commits into
trunkfrom
add/latest-posts-layout-support
Open

Add layout and block spacing support to Latest Posts block#77989
tellthemachines wants to merge 6 commits into
trunkfrom
add/latest-posts-layout-support

Conversation

@tellthemachines

@tellthemachines tellthemachines commented May 6, 2026

Copy link
Copy Markdown
Contributor

What?

Similar to #49050 and #77411.

Adds layout and block spacing support to Latest Posts to replace its custom list/grid styles.

Testing Instructions

  1. In trunk, add a Latest Posts block and configure its columns;
  2. Check out this branch and verify that the block looks the same as in trunk;
  3. Use the new layout controls to adjust column number and minimum column width, enabling responsive behaviour for columns;
  4. Check that setting minimum column width to 0 disables responsive columns altogether (column number shouldn't change with screen size).

Testing Instructions for Keyboard

Screenshots or screencast

(note that Layout panel is now in the Styles tab)

Before After
Screenshot 2026-05-18 at 12 04 00 pm Screenshot 2026-05-18 at 12 04 20 pm

Use of AI Tools

Written by GPT 5.5. leaving as a draft until I've reviewed it properly. this has now been human-reviewed.

@tellthemachines tellthemachines self-assigned this May 6, 2026
@tellthemachines tellthemachines added [Type] Enhancement A suggestion for improvement. [Block] Latest Posts Affects the Latest Posts Block [Feature] Layout Layout block support, its UI controls, and style output. labels May 6, 2026
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label May 6, 2026
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Size Change: +556 B (+0.01%)

Total Size: 8.46 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 323 kB +169 B (+0.05%)
build/styles/block-library/latest-posts/style-rtl.css 1.42 kB +68 B (+5.01%) 🔍
build/styles/block-library/latest-posts/style-rtl.min.css 586 B +66 B (+12.69%) ⚠️
build/styles/block-library/latest-posts/style.css 1.44 kB +68 B (+4.96%) 🔍
build/styles/block-library/latest-posts/style.min.css 585 B +65 B (+12.5%) ⚠️
build/styles/block-library/style-rtl.css 21.7 kB +36 B (+0.17%)
build/styles/block-library/style-rtl.min.css 18.2 kB +25 B (+0.14%)
build/styles/block-library/style.css 21.8 kB +34 B (+0.16%)
build/styles/block-library/style.min.css 18.2 kB +25 B (+0.14%)

compressed-size-action

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Flaky tests detected in 5b9e7e1.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27254655582
📝 Reported issues:

@tellthemachines tellthemachines force-pushed the add/latest-posts-layout-support branch from bb4677d to 92b61a7 Compare May 18, 2026 00:23
'string' !== typeof oldAttributes.categories
) {
return oldAttributes;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

had to add this check because we need to run this before the layout migration, and if we don't check whether categories actually exists it just goes and adds an array of them anyway

! postCount
? MAX_POSTS_COLUMNS
: Math.min( MAX_POSTS_COLUMNS, postCount )
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removing the old max here so it matches the Post Template controls.

[ `columns-${ columns }` ]: postLayout === 'grid',
[ `columns-${ columnCount }` ]:
layoutType === 'grid' && columnCount,
'has-native-responsive-grid':

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This block has the same responsive fallback as Post Template so we're adding the same back compat workaround.

@tellthemachines tellthemachines marked this pull request as ready for review May 18, 2026 02:07
@github-actions

github-actions Bot commented May 18, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

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: tellthemachines <isabel_brison@git.wordpress.org>
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.

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

It took me way too long to realize I had to click on the "grid" layout to test 🤦🏻

Question: does this make the existing postLayout and columns attributes in block.json deprecated? Do they stay there for any reason? (Assuming backwards compat)

...attributesWithoutLegacyLayout,
layout: {
type: postLayout === 'grid' ? 'grid' : 'default',
...( postLayout === 'grid' && columns && { columnCount: columns } ),

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.

Does there need to be a default here, or does it flow down from block.json? (column: 3)

E.g., columnCount: columns ?? 3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It'll be whatever is set on the legacy block, which might be that default from block.json or something else if user has changed it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah actually I think we should ensure the legacy attribs are present in the deprecation, then they can be removed from the block.json

},
migrate: ( oldAttributes ) =>
migratePostLayout( migrateCategories( oldAttributes ) ),
isEligible: ( { postLayout } ) => postLayout,

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.

Does the migration have to run just for 'grid' or all layouts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

all layouts because we're also converting the "list" layout to the "default" type.

html: false,
},
migrate: migrateCategories,
isEligible: ( { categories } ) =>

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.

Apologies, I haven't had my nose in deprecations for a long time.

Does this deprecation see the original raw attributes or the already-migrated attributes?

Just wondering if this will run on the original attributes and replace the migration result from before. If so maybe a ! postLayout check would stop that?

I don't know! 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As I understand it the migrations always run in sequence, so if the block is eligible for the categories migration it'll run that, and if it's eligible for the layout one it'll run categories and then layout on whatever categories spat out. I tested this on blocks with legacy layouts and it seemed to work fine.

@tellthemachines

Copy link
Copy Markdown
Contributor Author

It took me way too long to realize I had to click on the "grid" layout to test 🤦🏻

sorry, I didn't think to add that step explicitly 😅

Question: does this make the existing postLayout and columns attributes in block.json deprecated? Do they stay there for any reason? (Assuming backwards compat)

Oh I think they can be removed! Looking at #49050 as an example, we removed the displayLayout attrib from the Query block there.

@tellthemachines tellthemachines force-pushed the add/latest-posts-layout-support branch from 601548d to 932a668 Compare June 10, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Latest Posts Affects the Latest Posts Block [Feature] Layout Layout block support, its UI controls, and style output. [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants