Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Delay initial rendering of the inserters
  • Loading branch information
youknowriad committed May 19, 2022
commit 56affab568c11e5ab555acfe9c947403397d7e6f
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useEffect, useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -11,10 +12,25 @@ import { store as blockEditorStore } from '../../store';
import Inserter from '../inserter';

function ExplodedModeInserters( { __unstableContentRef } ) {
const [ isReady, setIsReady ] = useState( false );
const blockOrder = useSelect( ( select ) => {
return select( blockEditorStore ).getBlockOrder();
}, [] );

// Deffer the initial rendering to avoid the jumps due to the animation.
useEffect( () => {
const timeout = setTimeout( () => {
setIsReady( true );
}, 500 );
return () => {
clearTimeout( timeout );
};
}, [] );

if ( ! isReady ) {
return null;
}

return blockOrder.map( ( clientId, index ) => {
if ( index === blockOrder.length - 1 ) {
return null;
Expand Down