Skip to content

Commit

Permalink
Block Editor: Add useNoRecursiveRenders
Browse files Browse the repository at this point in the history
Originally introduced in #28405 to prevent Reusable Blocks from
infinitely and fatally recurring, React hook `useNoRecursiveRenders` has
a place in the block-editor package so that other block types
susceptible to recursion can be fixed too.
  • Loading branch information
mcsf committed Jan 22, 2021
1 parent e1972b0 commit 68b69d3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export { default as WritingFlow } from './writing-flow';
export { useCanvasClickRedirect as __unstableUseCanvasClickRedirect } from './use-canvas-click-redirect';
export { default as useBlockDisplayInformation } from './use-block-display-information';
export { default as __unstableIframe } from './iframe';
export { default as __experimentalUseNoRecursiveRenders } from './use-no-recursive-renders';

/*
* State Related Components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { render } from '@testing-library/react';
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';
import { __experimentalUseNoRecursiveRenders as useNoRecursiveRenders } from '@wordpress/block-editor';

// Mimics a block's Edit component, such as ReusableBlockEdit, which is capable
// of calling itself depending on its `ref` attribute.
Expand Down Expand Up @@ -37,11 +38,6 @@ function Edit( { attributes: { ref } } ) {
);
}

/**
* Internal dependencies
*/
import useNoRecursiveRenders from '../use-no-recursive-renders';

describe( 'useNoRecursiveRenders', () => {
it( 'allows a single block to render', () => {
const { container } = render(
Expand Down
6 changes: 1 addition & 5 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { __ } from '@wordpress/i18n';
import {
__experimentalUseInnerBlocksProps as useInnerBlocksProps,
__experimentalUseNoRecursiveRenders as useNoRecursiveRenders,
InnerBlocks,
BlockControls,
InspectorControls,
Expand All @@ -26,11 +27,6 @@ import {
} from '@wordpress/block-editor';
import { store as reusableBlocksStore } from '@wordpress/reusable-blocks';

/**
* Internal dependencies
*/
import useNoRecursiveRenders from './use-no-recursive-renders';

export default function ReusableBlockEdit( { attributes: { ref }, clientId } ) {
const [ hasAlreadyRendered, RecursionProvider ] = useNoRecursiveRenders(
ref
Expand Down

0 comments on commit 68b69d3

Please sign in to comment.