Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Fix block highlight rendering after block is moved #23425

Merged
merged 13 commits into from
Jul 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions packages/block-editor/src/components/block-toolbar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import { noop } from 'lodash';
import { useDispatch } from '@wordpress/data';
import { useState, useRef, useEffect, useCallback } from '@wordpress/element';

const {
clearTimeout,
requestAnimationFrame,
cancelAnimationFrame,
setTimeout,
} = window;
const { clearTimeout, setTimeout } = window;
const DEBOUNCE_TIMEOUT = 250;

/**
Expand Down Expand Up @@ -169,8 +164,6 @@ export function useShowMoversGestures( {
};
}

let requestAnimationFrameId;

/**
* Hook that toggles the highlight (outline) state of a block
*
Expand All @@ -189,20 +182,8 @@ export function useToggleBlockHighlight( clientId ) {
);

useEffect( () => {
// On mount, we make sure to cancel any pending animation frame request
// that hasn't been completed yet. Components like NavigableToolbar may
// mount and unmount quickly.
if ( requestAnimationFrameId ) {
cancelAnimationFrame( requestAnimationFrameId );
}
return () => {
// Sequences state change to enable editor updates (e.g. cursor
// position) to render correctly.
requestAnimationFrameId = requestAnimationFrame( () => {
updateBlockHighlight( false );
} );
};
}, [] );
return () => updateBlockHighlight( false );
}, [ updateBlockHighlight ] );

return updateBlockHighlight;
}