Block Editor: Flatten, shortcut align hook rendering if unaligned #18963
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request seeks to optimize the implementation of the block alignment
BlockListBlock
filtered higher-order component.It seeks to improve performance in two ways:
compose
flow ofwithSelect
and an inner component, to a single component usinguseSelect
.align
attribute, in order to skip logic involved in validating alignment value (skips calls togetValidAlignments
,getBlockSupport
,hasBlockSupport
, and anincludes
iteration on thevalidAlignments
result).The aim here is to optimize that the majority of blocks will not have an alignment value, and can skip this hook logic.
There might be some way to optimize this even further:
useSelect
hook is rendered, to avoid another store subscription. Since the hook cannot be conditionally rendered, this might have to be part of a separate component or higher-order component, which loses some of the benefit in flattening the hierarchy.BlockEditBlock
, rather than filtering at all. The advantage of the filtering here is in colocating all of the alignments behavior, but there may be an alternative approach we could consider which doesn't have the same overhead as the filter.Testing Instructions:
Verify there are no regressions in the rendering of a block, notably on valid alignments of a block, e.g. in themes with and without wide alignment support (should not show as wide-aligned in the editor if the theme doesn't support it).
Ensure unit tests pass: