Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement default algorithm
  • Loading branch information
getdave committed Dec 5, 2024
commit fa9ef34ba516b01d2f063edc77ed4ebcf1ef62d4
20 changes: 18 additions & 2 deletions packages/block-editor/src/store/private-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
getClientIdsWithDescendants,
isNavigationMode,
getBlockRootClientId,
getBlocksByName,
getBlockAttributes,
} from './selectors';
import {
checkAllowListRecursive,
Expand Down Expand Up @@ -563,10 +565,24 @@ export const getBlockStyles = createSelector(
*
* @param {Object} state Editor state.
*
* @return {string|undefined} The section root client ID or undefined if not set.
* @return {string} The section root client ID.
*/
export function getSectionRootClientId( state ) {
return state.settings?.[ sectionRootClientIdKey ];
const settingsRootClientId = state.settings?.[ sectionRootClientIdKey ];

// Specifically check that the setting was not provided to avoid
// cases where the provided setting is an empty string to signify
// the "root block" of the editor.
if ( settingsRootClientId !== undefined ) {
return settingsRootClientId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we explicitly provide "" as a settingsRootClientId in the post editor today or do we leave that to the block-editor's algorithm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @wordpress/editor provides the setting, today Site and Post Editors would use the algorithm that looks for main.

However, if the rendering mode is template-locked (like when you are editing a Page in the Site Editor) then the default would be '' (empty string).

I think the question is here

Copy link
Contributor

Choose a reason for hiding this comment

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

Main main question is about "performance". In other words, it seems unnecessary to run the fallback for post and page editors in "post-only" mode (not template-locked), for template-locked, I suspect that we already have something that sets the "post-content" block as section root.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean. If we are in Post Editor (Posts or Pages or whatever) we are in post-only mode. Therefore we're going to be looking for a main tag which is very unlikely to exist.

Yes maybe I need to do some more digging to find where these editors end up with '' as the sectionRootClientId.

}

return (
getBlocksByName( state, 'core/group' ).find(
( clientId ) =>
getBlockAttributes( state, clientId )?.tagName === 'main'
) ?? ''
);
}

/**
Expand Down