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

Block Editor: Fix ESLint warnings for the 'useInnerBlockTemplateSync' hook #68355

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all 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
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,
] );
}
Loading