From 5526d0c5d24b81752c106765a9c7c49fc15c451b Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Sat, 1 Aug 2020 09:59:17 +0800 Subject: [PATCH] Improve rootClientId comparison in useBlockDropZone (#24307) * Default to an empty string for targetRootClientId * Fix typo --- .../src/components/use-block-drop-zone/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/use-block-drop-zone/index.js b/packages/block-editor/src/components/use-block-drop-zone/index.js index 7ff5496acca120..93a1688139e43a 100644 --- a/packages/block-editor/src/components/use-block-drop-zone/index.js +++ b/packages/block-editor/src/components/use-block-drop-zone/index.js @@ -171,7 +171,11 @@ function parseDropEvent( event ) { */ export default function useBlockDropZone( { element, - rootClientId: targetRootClientId, + // An undefined value represents a top-level block. Default to an empty + // string for this so that `targetRootClientId` can be easily compared to + // values returned by the `getRootBlockClientId` selector, which also uses + // an empty string to represent top-level blocks. + rootClientId: targetRootClientId = '', } ) { const [ targetBlockIndex, setTargetBlockIndex ] = useState( null ); @@ -285,16 +289,11 @@ export default function useBlockDropZone( { return; } - const isAtSameLevel = - sourceRootClientId === targetRootClientId || - ( sourceRootClientId === '' && - targetRootClientId === undefined ); - - const draggedBlockCount = sourceClientIds.length; - // If the block is kept at the same level and moved downwards, // subtract to take into account that the blocks being dragged // were removed from the block list. + const isAtSameLevel = sourceRootClientId === targetRootClientId; + const draggedBlockCount = sourceClientIds.length; const insertIndex = isAtSameLevel && sourceBlockIndex < targetBlockIndex ? targetBlockIndex - draggedBlockCount