From 0a50173976da593696918294ace3c28a1255c19a Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Fri, 16 Jun 2023 20:28:25 +0800 Subject: [PATCH] Fix infinite redirect from homescreen to core profiler (#38768) * Fix infinite redirect using useEffect to remove unintentional rerendering * Changelog --- .../woocommerce-admin/client/homescreen/index.tsx | 14 +++++++++++--- .../fix-infinite-redirect-to-core-profiler | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-infinite-redirect-to-core-profiler diff --git a/plugins/woocommerce-admin/client/homescreen/index.tsx b/plugins/woocommerce-admin/client/homescreen/index.tsx index a9d80c505d4..cfd944ec13f 100644 --- a/plugins/woocommerce-admin/client/homescreen/index.tsx +++ b/plugins/woocommerce-admin/client/homescreen/index.tsx @@ -3,12 +3,14 @@ */ import { compose } from '@wordpress/compose'; import { withSelect } from '@wordpress/data'; +import { useEffect } from '@wordpress/element'; import { ONBOARDING_STORE_NAME, withOnboardingHydration, WCDataSelector, } from '@woocommerce/data'; import { getHistory, getNewPath, useQuery } from '@woocommerce/navigation'; + /** * Internal dependencies */ @@ -26,9 +28,15 @@ const Homescreen = ( { } = {}, hasFinishedResolution, }: HomescreenProps ) => { - if ( hasFinishedResolution && ! profilerCompleted && ! profilerSkipped ) { - getHistory().push( getNewPath( {}, '/setup-wizard', {} ) ); - } + useEffect( () => { + if ( + hasFinishedResolution && + ! profilerCompleted && + ! profilerSkipped + ) { + getHistory().push( getNewPath( {}, '/setup-wizard', {} ) ); + } + }, [ hasFinishedResolution, profilerCompleted, profilerSkipped ] ); const query = useQuery(); // @ts-expect-error Layout is a pure JS component diff --git a/plugins/woocommerce/changelog/fix-infinite-redirect-to-core-profiler b/plugins/woocommerce/changelog/fix-infinite-redirect-to-core-profiler new file mode 100644 index 00000000000..808fb09e3c8 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-infinite-redirect-to-core-profiler @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix infinite redirect from homescreen when onboarding isn't completed using useEffect to remove unintentional rerendering