From ec85c4bd4ab57c824eb993ba093582f2a2e61506 Mon Sep 17 00:00:00 2001 From: louwie17 Date: Fri, 12 Jan 2024 17:13:22 -0400 Subject: [PATCH] Fix variations initial load (#43583) * Retrieve new variations if not already generating * Add changelog * Fix lint error --- .../changelog/fix-variations_initial_load | 4 ++++ .../product-editor/src/blocks/generic/section/edit.tsx | 1 - .../variations-table/use-variations/use-variations.ts | 10 ++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 packages/js/product-editor/changelog/fix-variations_initial_load diff --git a/packages/js/product-editor/changelog/fix-variations_initial_load b/packages/js/product-editor/changelog/fix-variations_initial_load new file mode 100644 index 00000000000..cecb719ccba --- /dev/null +++ b/packages/js/product-editor/changelog/fix-variations_initial_load @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Fix issue when generating variations for the first time in the new editor. diff --git a/packages/js/product-editor/src/blocks/generic/section/edit.tsx b/packages/js/product-editor/src/blocks/generic/section/edit.tsx index 0100c6365a8..92920eb66c8 100644 --- a/packages/js/product-editor/src/blocks/generic/section/edit.tsx +++ b/packages/js/product-editor/src/blocks/generic/section/edit.tsx @@ -21,7 +21,6 @@ import { ProductEditorBlockEditProps } from '../../../types'; export function SectionBlockEdit( { attributes, - clientId, }: ProductEditorBlockEditProps< SectionBlockAttributes > ) { const { description, title, blockGap } = attributes; diff --git a/packages/js/product-editor/src/components/variations-table/use-variations/use-variations.ts b/packages/js/product-editor/src/components/variations-table/use-variations/use-variations.ts index 4d4ec58ea81..9af662f08c2 100644 --- a/packages/js/product-editor/src/components/variations-table/use-variations/use-variations.ts +++ b/packages/js/product-editor/src/components/variations-table/use-variations/use-variations.ts @@ -70,10 +70,6 @@ export function useVariations( { productId }: UseVariationsProps ) { } } - useEffect( () => { - getCurrentVariationsPage( { product_id: productId } ); - }, [ productId ] ); - function onPageChange( page: number ) { getCurrentVariationsPage( { product_id: productId, @@ -458,6 +454,12 @@ export function useVariations( { productId }: UseVariationsProps ) { const wasGenerating = useRef( false ); + useEffect( () => { + if ( ! isGenerating ) { + getCurrentVariationsPage( { product_id: productId } ); + } + }, [ productId, isGenerating ] ); + useEffect( () => { if ( isGenerating ) { clearFilters();