Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Experiment with proposed fix to useForcedLayout #7637

Closed
senadir opened this issue Nov 9, 2022 · 1 comment
Closed

Experiment with proposed fix to useForcedLayout #7637

senadir opened this issue Nov 9, 2022 · 1 comment
Labels
type: enhancement The issue is a request for an enhancement.

Comments

@senadir
Copy link
Member

senadir commented Nov 9, 2022

In pca54o-4GY-p2#comment-4658 Jarda proposed a refactor to useForcedLayout that would eliminate the need for complex state management and would just batch things using pure JS.

This is a simplified version of that code, keep note that useForcedLayout should still take into account existing templates and block placement.

function useForcedLayout( clientId ) {
  const registry = useRegistry();
  useEffect( () => {
    const unsub = registry.subscribe( () => {
      const innerBlocks = registry.select( 'core/block-editor' ).getBlocks( clientId );
      const missingBlocks = getMissingBlocks( innerBlocks );
      for ( const block of missingBlocks ) {
        registry.dispatch( 'core/block-editor' ).appendBlock( block );
      }
    } );
    return () => unsub();
  }, [ clientId, registry ] );
}
@alexflorisca
Copy link
Member

This was addressed in #7879

@alexflorisca alexflorisca removed their assignment Dec 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants