diff --git a/plugins/woocommerce-admin/changelogs/fix-8029-ensure-redirect-to-setup-wizard-stably b/plugins/woocommerce-admin/changelogs/fix-8029-ensure-redirect-to-setup-wizard-stably new file mode 100644 index 00000000000..64d6e8b37e8 --- /dev/null +++ b/plugins/woocommerce-admin/changelogs/fix-8029-ensure-redirect-to-setup-wizard-stably @@ -0,0 +1,4 @@ +Significance: patch +Type: Fix + +Ensure setup-wizard redirection on homescreen is stable. #8114 diff --git a/plugins/woocommerce-admin/client/homescreen/index.tsx b/plugins/woocommerce-admin/client/homescreen/index.tsx index 799d5db2de6..20946d62cbb 100644 --- a/plugins/woocommerce-admin/client/homescreen/index.tsx +++ b/plugins/woocommerce-admin/client/homescreen/index.tsx @@ -18,13 +18,19 @@ import type { History } from 'history'; import Layout from './layout'; type HomescreenProps = ReturnType< typeof withSelectHandler > & { + hasFinishedResolution: boolean; query: Record< string, string >; }; -const Homescreen = ( { profileItems, query }: HomescreenProps ) => { - const { completed: profilerCompleted, skipped: profilerSkipped } = - profileItems || {}; - if ( ! profilerCompleted && ! profilerSkipped ) { +const Homescreen = ( { + profileItems: { + completed: profilerCompleted, + skipped: profilerSkipped, + } = {}, + hasFinishedResolution, + query, +}: HomescreenProps ) => { + if ( hasFinishedResolution && ! profilerCompleted && ! profilerSkipped ) { ( getHistory() as History ).push( getNewPath( {}, '/setup-wizard', {} ) ); @@ -36,10 +42,14 @@ const Homescreen = ( { profileItems, query }: HomescreenProps ) => { const onboardingData = getSetting( 'onboarding', {} ); const withSelectHandler = ( select: WCDataSelector ) => { - const { getProfileItems } = select( ONBOARDING_STORE_NAME ); - const profileItems = getProfileItems(); + const { getProfileItems, hasFinishedResolution } = select( + ONBOARDING_STORE_NAME + ); - return { profileItems }; + return { + profileItems: getProfileItems(), + hasFinishedResolution: hasFinishedResolution( 'getProfileItems', [] ), + }; }; export default compose(