Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Prevent useForcedLayout breaking in WP 6.1 #7447

Merged
merged 1 commit into from
Oct 21, 2022
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
8 changes: 2 additions & 6 deletions assets/js/blocks/cart-checkout-shared/use-forced-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
useRef,
useCallback,
useMemo,
useState,
} from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import {
Expand Down Expand Up @@ -42,8 +41,6 @@ export const useForcedLayout = ( {
} ): void => {
const currentRegisteredBlocks = useRef( registeredBlocks );
const currentDefaultTemplate = useRef( defaultTemplate );
const [ forcedBlocksInserted, setForcedBlocksInserted ] =
useState< number >( 0 );

const { insertBlock, replaceInnerBlocks } =
useDispatch( 'core/block-editor' );
Expand All @@ -58,18 +55,17 @@ export const useForcedLayout = ( {
),
};
},
[ clientId, currentRegisteredBlocks.current, forcedBlocksInserted ]
[ clientId, currentRegisteredBlocks.current ]
);

const appendBlock = useCallback(
( block, position ) => {
const newBlock = createBlock( block.name );
insertBlock( newBlock, position, clientId, false );
setForcedBlocksInserted( forcedBlocksInserted + 1 );
},
// We need to skip insertBlock here due to a cache issue in wordpress.com that causes an inifinite loop, see https://github.com/Automattic/wp-calypso/issues/66092 for an expanded doc.
// eslint-disable-next-line react-hooks/exhaustive-deps
[ clientId, forcedBlocksInserted ]
[ clientId ]
);

const lockedBlockTypes = useMemo(
Expand Down