Skip to content

Improving the algorithm for detecting the "Section Root"  #65400

@getdave

Description

@getdave

Recent efforts around Zoom Out and "Content Only" Select Mode have put more focus on the concept of the "Section Root".

The "Section Root" is loosely defined as the block which represents the "main content" of the post/page/template you are working on. It is the parent of all the "sections" of the post.

The current algorithm used to detect this is:

function getSectionRootBlock() {
if ( renderingMode === 'template-locked' ) {
return getBlocksByName( 'core/post-content' )?.[ 0 ] ?? '';
}
return (
getBlocksByName( 'core/group' ).find(
( clientId ) =>
getBlockAttributes( clientId )?.tagName === 'main'
) ?? ''
);
}

It considers:

  • core/post-content if it's a page
  • the <main> tag for anything else

As not all Themes/Sites will use a standard setup (arrange of blocks, usage of tags...etc) we should try and make small improvements that capture some of the most common cases.

We can not (and should not) try to capture every possible use case, because that will be impossible.

The features that make use of the "section root" are:

Todo

We need some concrete examples of edge cases around detecting the “section root” in the Editor.

For example some folks mentioned some Themes are throwing a wrapping div around things or not using <main>…etc. We need to gather some specifics.

Pinging @WordPress/gutenberg-design

Examples

[Please list examples below]

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions