From f9035e533f01c6df46d00f724093851d95a29735 Mon Sep 17 00:00:00 2001 From: Jose Amietta Date: Fri, 3 Jan 2025 12:29:33 -0300 Subject: [PATCH] Remove useCustomerWishlistSkus hook from Carousel and Gallery components and add in useApp talon to avoid infinite loop --- .../Products/Carousel/__tests__/useCarousel.spec.js | 7 ------- .../lib/ContentTypes/Products/Carousel/useCarousel.js | 4 ---- packages/peregrine/lib/talons/App/__tests__/useApp.spec.js | 7 +++++++ packages/peregrine/lib/talons/App/useApp.js | 3 +++ .../lib/talons/Gallery/__tests__/useGallery.spec.js | 7 ------- packages/peregrine/lib/talons/Gallery/useGallery.js | 4 ---- 6 files changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/pagebuilder/lib/ContentTypes/Products/Carousel/__tests__/useCarousel.spec.js b/packages/pagebuilder/lib/ContentTypes/Products/Carousel/__tests__/useCarousel.spec.js index 94a4d76950..3b16ca703f 100644 --- a/packages/pagebuilder/lib/ContentTypes/Products/Carousel/__tests__/useCarousel.spec.js +++ b/packages/pagebuilder/lib/ContentTypes/Products/Carousel/__tests__/useCarousel.spec.js @@ -15,13 +15,6 @@ import defaultOperations from '../carousel.gql'; import mosOperations from '../carousel.gql.ce'; import acOperations from '../carousel.gql.ee'; -jest.mock( - '@magento/peregrine/lib/hooks/useCustomerWishlistSkus/useCustomerWishlistSkus', - () => ({ - useCustomerWishlistSkus: jest.fn() - }) -); - const cache = new InMemoryCache({ typePolicies }); diff --git a/packages/pagebuilder/lib/ContentTypes/Products/Carousel/useCarousel.js b/packages/pagebuilder/lib/ContentTypes/Products/Carousel/useCarousel.js index 25998c955c..e72e987cdd 100644 --- a/packages/pagebuilder/lib/ContentTypes/Products/Carousel/useCarousel.js +++ b/packages/pagebuilder/lib/ContentTypes/Products/Carousel/useCarousel.js @@ -1,7 +1,5 @@ import { useQuery } from '@apollo/client'; -import { useCustomerWishlistSkus } from '@magento/peregrine/lib/hooks/useCustomerWishlistSkus/useCustomerWishlistSkus'; - import mergeOperations from '@magento/peregrine/lib/util/shallowMerge'; import defaultOperations from './carousel.gql'; @@ -11,8 +9,6 @@ import defaultOperations from './carousel.gql'; export const useCarousel = (props = {}) => { const operations = mergeOperations(defaultOperations, props.operations); - useCustomerWishlistSkus(); - const { data: storeConfigData } = useQuery(operations.getStoreConfigQuery, { fetchPolicy: 'cache-and-network' }); diff --git a/packages/peregrine/lib/talons/App/__tests__/useApp.spec.js b/packages/peregrine/lib/talons/App/__tests__/useApp.spec.js index d40d73d7bd..55f1d4624c 100644 --- a/packages/peregrine/lib/talons/App/__tests__/useApp.spec.js +++ b/packages/peregrine/lib/talons/App/__tests__/useApp.spec.js @@ -16,6 +16,13 @@ useHistory.mockImplementation(() => ({ go: reload })); +jest.mock( + '@magento/peregrine/lib/hooks/useCustomerWishlistSkus/useCustomerWishlistSkus', + () => ({ + useCustomerWishlistSkus: jest.fn() + }) +); + jest.mock('@magento/peregrine/lib/context/app', () => { const state = { drawerClosed: false, diff --git a/packages/peregrine/lib/talons/App/useApp.js b/packages/peregrine/lib/talons/App/useApp.js index 5b429f6bf4..25ebb77bc9 100644 --- a/packages/peregrine/lib/talons/App/useApp.js +++ b/packages/peregrine/lib/talons/App/useApp.js @@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo } from 'react'; import { useHistory } from 'react-router-dom'; import errorRecord from '@magento/peregrine/lib/util/createErrorRecord'; +import { useCustomerWishlistSkus } from '@magento/peregrine/lib/hooks/useCustomerWishlistSkus/useCustomerWishlistSkus'; import { useAppContext } from '@magento/peregrine/lib/context/app'; const dismissers = new WeakMap(); @@ -41,6 +42,8 @@ export const useApp = props => { } = props; const history = useHistory(); + useCustomerWishlistSkus(); + const reload = useCallback(() => { if (process.env.NODE_ENV !== 'development') { history.go(0); diff --git a/packages/peregrine/lib/talons/Gallery/__tests__/useGallery.spec.js b/packages/peregrine/lib/talons/Gallery/__tests__/useGallery.spec.js index f873f15c97..36aa29254a 100644 --- a/packages/peregrine/lib/talons/Gallery/__tests__/useGallery.spec.js +++ b/packages/peregrine/lib/talons/Gallery/__tests__/useGallery.spec.js @@ -15,13 +15,6 @@ import defaultOperations from '../gallery.gql'; import mosOperations from '../gallery.gql.ce'; import acOperations from '../gallery.gql.ee'; -jest.mock( - '../../../hooks/useCustomerWishlistSkus/useCustomerWishlistSkus', - () => ({ - useCustomerWishlistSkus: jest.fn() - }) -); - const cache = new InMemoryCache({ typePolicies }); diff --git a/packages/peregrine/lib/talons/Gallery/useGallery.js b/packages/peregrine/lib/talons/Gallery/useGallery.js index 4c0f4c644d..8a8e69ddf2 100644 --- a/packages/peregrine/lib/talons/Gallery/useGallery.js +++ b/packages/peregrine/lib/talons/Gallery/useGallery.js @@ -1,15 +1,11 @@ import { useQuery } from '@apollo/client'; -import { useCustomerWishlistSkus } from '../../hooks/useCustomerWishlistSkus/useCustomerWishlistSkus'; - import mergeOperations from '../../util/shallowMerge'; import defaultOperations from './gallery.gql'; export const useGallery = (props = {}) => { const operations = mergeOperations(defaultOperations, props.operations); - useCustomerWishlistSkus(); - const { data: storeConfigData } = useQuery(operations.getStoreConfigQuery, { fetchPolicy: 'cache-and-network' });