Skip to content

Commit

Permalink
useScrollIntoView: check if element is mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 14, 2021
1 parent 54462de commit da230b9
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ 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;
}

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 ) ) {
Expand Down

0 comments on commit da230b9

Please sign in to comment.