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 (#68355)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: up1512001 <up1512001@git.wordpress.org>
  • Loading branch information
3 people authored Dec 27, 2024
1 parent 011e7af commit f95f5ee
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,
] );
}

1 comment on commit f95f5ee

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in f95f5ee.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12518661371
📝 Reported issues:

Please sign in to comment.