Skip to content

Commit

Permalink
fix: handle deeply nested image blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Jul 9, 2020
1 parent 0bbe397 commit d846beb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/editor/blocks/posts-inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ const PostsInserterBlock = ( {
removeBlock,
} ) => {
const [ isReady, setIsReady ] = useState( ! attributes.displayFeaturedImage );
const stringifiedPostList = JSON.stringify( postList );

// Stringify added to minimize flicker.
const templateBlocks = useMemo( () => getTemplateBlocks( postList, attributes ), [
JSON.stringify( postList ),
stringifiedPostList,
attributes,
] );

const stringifiedTemplateBlocks = JSON.stringify( templateBlocks );

useEffect(() => {
const { isDisplayingSpecificPosts, specificPosts } = attributes;

Expand Down Expand Up @@ -81,14 +84,14 @@ const PostsInserterBlock = ( {
}

// Wait for image blocks to be added to the BlockPreview.
const imageBlocks = templateBlocks.filter( block => 'core/image' === block.name );
const imageBlocks = stringifiedTemplateBlocks.match( /\"name\":\"core\/image\"/g ) || [];

// Preview is ready once all image blocks are accounted for.
if ( imageBlocks.length === images.length ) {
setIsReady( true );
}
}
}, [ JSON.stringify( postList ), JSON.stringify( templateBlocks ) ]);
}, [ stringifiedPostList, stringifiedTemplateBlocks ]);

const innerBlocksToInsert = templateBlocks.map( convertBlockSerializationFormat );
useEffect(() => {
Expand Down

0 comments on commit d846beb

Please sign in to comment.