Skip to content

Commit

Permalink
Block Editor: Fix ESLint warnings for the 'useInnerBlockTemplateSync'…
Browse files Browse the repository at this point in the history
… hook (WordPress#68355)


Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: up1512001 <[email protected]>
  • Loading branch information
3 people authored and Gulamdastgir-Momin committed Jan 23, 2025
1 parent c64e520 commit 84ffcd6
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fastDeepEqual from 'fast-deep-equal/es6';
* WordPress dependencies
*/
import { useRef, useLayoutEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { useRegistry } from '@wordpress/data';
import { synchronizeBlocksWithTemplate } from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -42,21 +42,22 @@ export default function useInnerBlockTemplateSync(
) {
// Instead of adding a useSelect mapping here, please add to the useSelect
// mapping in InnerBlocks! Every subscription impacts performance.

const {
getBlocks,
getSelectedBlocksInitialCaretPosition,
isBlockSelected,
} = useSelect( blockEditorStore );
const { replaceInnerBlocks, __unstableMarkNextChangeAsNotPersistent } =
useDispatch( blockEditorStore );
const registry = useRegistry();

// Maintain a reference to the previous value so we can do a deep equality check.
const existingTemplateRef = useRef( null );

useLayoutEffect( () => {
let isCancelled = false;

const {
getBlocks,
getSelectedBlocksInitialCaretPosition,
isBlockSelected,
} = registry.select( blockEditorStore );
const { replaceInnerBlocks, __unstableMarkNextChangeAsNotPersistent } =
registry.dispatch( blockEditorStore );

// There's an implicit dependency between useInnerBlockTemplateSync and useNestedSettingsUpdate
// The former needs to happen after the latter and since the latter is using microtasks to batch updates (performance optimization),
// we need to schedule this one in a microtask as well.
Expand Down Expand Up @@ -110,5 +111,11 @@ export default function useInnerBlockTemplateSync(
return () => {
isCancelled = true;
};
}, [ template, templateLock, clientId ] );
}, [
template,
templateLock,
clientId,
registry,
templateInsertUpdatesSelection,
] );
}

0 comments on commit 84ffcd6

Please sign in to comment.