Skip to content

Commit

Permalink
Implement full algorithm for sectionRootClientId
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Aug 16, 2024
1 parent 3802aa6 commit 56292e8
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,31 @@ export const ExperimentalEditorProvider = withRegistryProvider(
setRenderingMode,
} = unlock( useDispatch( editorStore ) );

const { computedSectionRootClientId } = useSelect( ( select ) => {
const { getBlockAttributes, getBlocksByName } =
select( blockEditorStore );
const { computedSectionRootClientId } = useSelect(
( select ) => {
const { getBlockAttributes, getBlocksByName } =
select( blockEditorStore );

const _sectionRootClientId =
getBlocksByName( 'core/group' ).find(
( clientId ) =>
getBlockAttributes( clientId )?.tagName === 'main'
) ?? '';
let _sectionRootClientId;

return {
computedSectionRootClientId: _sectionRootClientId,
};
}, [] );
if ( mode === 'template-locked' ) {
_sectionRootClientId =
getBlocksByName( 'core/post-content' )?.[ 0 ] ?? '';
} else {
_sectionRootClientId =
getBlocksByName( 'core/group' ).find(
( clientId ) =>
getBlockAttributes( clientId )?.tagName ===
'main'
) ?? '';
}

return {
computedSectionRootClientId: _sectionRootClientId,
};
},
[ mode ]
);

const { setSectionRootClientId } = unlock(
useDispatch( blockEditorStore )
Expand Down

0 comments on commit 56292e8

Please sign in to comment.