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 8 commits
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
11 changes: 6 additions & 5 deletions packages/block-editor/src/components/block-toolbar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { useDispatch } from '@wordpress/data';
import { useState, useRef, useEffect, useCallback } from '@wordpress/element';

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

const DEBOUNCE_TIMEOUT = 200;

/**
* Hook that creates a showMover state, as well as debounced show/hide callbacks.
Expand Down Expand Up @@ -169,8 +170,6 @@ export function useShowMoversGestures( {
};
}

let requestAnimationFrameId;

/**
* Hook that toggles the highlight (outline) state of a block
*
Expand All @@ -180,6 +179,7 @@ let requestAnimationFrameId;
*/
export function useToggleBlockHighlight( clientId ) {
const { toggleBlockHighlight } = useDispatch( 'core/block-editor' );
let requestAnimationFrameId;

const updateBlockHighlight = useCallback(
( isFocused ) => {
Expand All @@ -195,14 +195,15 @@ export function useToggleBlockHighlight( clientId ) {
if ( requestAnimationFrameId ) {
cancelAnimationFrame( requestAnimationFrameId );
}

return () => {
// Sequences state change to enable editor updates (e.g. cursor
// position) to render correctly.
requestAnimationFrameId = requestAnimationFrame( () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this cancelled?

Copy link
Author

@ItsJonQ ItsJonQ Jul 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellatrix I paused on this for now, as regardless of whether I use RAF or not, a couple of particular E2E tests keep failing. They fail when they attempt to use the toggleBlockHighlight action in a useCallback return.

Edit: Nevermind. I think we may need RAF

updateBlockHighlight( false );
} );
};
}, [] );
}, [ updateBlockHighlight ] );

return updateBlockHighlight;
}