Skip to content

Commit

Permalink
Suppress console warnings when unmounting refs
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jan 14, 2021
1 parent 00a27f2 commit 270f0ee
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export default function InsertionPoint( ref ) {
ref.current.addEventListener( 'mousemove', onMouseMove );

return () => {
ref.current.removeEventListener( 'mousemove', onMouseMove );
ref.current?.removeEventListener( 'mousemove', onMouseMove );
};
}, [ enableMouseMove, onMouseMove ] );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function useEventHandlers( ref, clientId ) {
ref.current.addEventListener( 'focusin', onFocus );

return () => {
ref.current.removeEventListener( 'focusin', onFocus );
ref.current?.removeEventListener( 'focusin', onFocus );
};
}

Expand Down Expand Up @@ -130,9 +130,9 @@ export function useEventHandlers( ref, clientId ) {
ref.current.addEventListener( 'dragstart', onDragStart );

return () => {
ref.current.removeEventListener( 'mouseleave', onMouseLeave );
ref.current.removeEventListener( 'keydown', onKeyDown );
ref.current.removeEventListener( 'dragstart', onDragStart );
ref.current?.removeEventListener( 'mouseleave', onMouseLeave );
ref.current?.removeEventListener( 'keydown', onKeyDown );
ref.current?.removeEventListener( 'dragstart', onDragStart );
};
}, [
isSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function useToolbarFocus(
}
return () => {
window.cancelAnimationFrame( raf );
if ( ! onIndexChange ) return;
if ( ! onIndexChange || ! ref.current ) return;
// When the toolbar element is unmounted and onIndexChange is passed, we
// pass the focused toolbar item index so it can be hydrated later.
const items = getAllToolbarItemsIn( ref.current );
Expand Down

0 comments on commit 270f0ee

Please sign in to comment.