From 0c028b4a8703d33d658c9cec84c263ca8a87acc0 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Thu, 6 Jan 2022 09:47:09 +0800 Subject: [PATCH] Add resolution check to ensure setup-wizard redirection on homescreen is stable (https://github.com/woocommerce/woocommerce-admin/pull/8114) * Add resolution check to ensure setup-wizard redirection is stable * Add changelogs --- ...029-ensure-redirect-to-setup-wizard-stably | 4 ++++ .../client/homescreen/index.tsx | 24 +++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 plugins/woocommerce-admin/changelogs/fix-8029-ensure-redirect-to-setup-wizard-stably 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(