diff --git a/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js b/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js index 3af1dfea024962..dc2c83bab21057 100644 --- a/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js +++ b/packages/block-editor/src/components/block-list/use-block-props/use-scroll-into-view.js @@ -34,6 +34,9 @@ export function useScrollIntoView( clientId ) { [ clientId ] ); + // Note that we can't use `useRefEffect` here, since an element change does + // not mean we can scroll. `isSelectionEnd` should be the sole dependency, + // while with `useRefEffect`, the element is a dependency as well. useEffect( () => { if ( ! isSelectionEnd ) { return; @@ -41,6 +44,10 @@ export function useScrollIntoView( clientId ) { const extentNode = ref.current; + if ( ! extentNode ) { + return; + } + // If the block is focused, the browser will already have scrolled into // view if necessary. if ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {