From 0c8d4cd0898511a2743a1fb3ac86dfb10fbf5098 Mon Sep 17 00:00:00 2001 From: Seghir Nadir Date: Tue, 11 Oct 2022 18:04:55 +0100 Subject: [PATCH] Add temporary workaround to fix inserting Cart block in WordPress.com (https://github.com/woocommerce/woocommerce-blocks/pull/7367) * remove problematic actions as deps * add inline docs * add todo comment --- .../cart-checkout-shared/use-forced-layout.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts index 35787c8870c..47208c98127 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts +++ b/plugins/woocommerce-blocks/assets/js/blocks/cart-checkout-shared/use-forced-layout.ts @@ -67,7 +67,9 @@ export const useForcedLayout = ( { insertBlock( newBlock, position, clientId, false ); setForcedBlocksInserted( forcedBlocksInserted + 1 ); }, - [ clientId, insertBlock, forcedBlocksInserted ] + // 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 ] ); const lockedBlockTypes = useMemo( @@ -144,11 +146,10 @@ export const useForcedLayout = ( { break; } } ); - }, [ - clientId, - innerBlocks, - lockedBlockTypes, - replaceInnerBlocks, - appendBlock, - ] ); + /* + We need to skip replaceInnerBlocks 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. + @todo Add replaceInnerBlocks and insertBlock after fixing https://github.com/Automattic/wp-calypso/issues/66092 + */ + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ clientId, innerBlocks, lockedBlockTypes, appendBlock ] ); };