Core profiler: set default for props to avoid crashes (#49519)

* fix(core-profiler): set default for props to avoid crashes. Fixes #49512

This fix solves an issue where if some of the onboarding profile properties from the context are undefined, it will prevent the user from proceeding with the core profiler. 

Related issue #49512 has a description of the issue.

* Add changefile(s) from automation for the following project(s): woocommerce

* feat(core-profiler): improve onboarding profile assignment logic

This commit improves the logic for assigning the onboarding profile in the core profiler. It now checks if the output of the event is an object before assigning it to the context. If the output is not an object, it keeps the existing context. This prevents crashes and allows the user to proceed with the core profiler.

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Chi-Hsuan Huang <chihsuan.tw@gmail.com>
This commit is contained in:
Elio Rivero 2024-07-23 04:45:58 +02:00 committed by GitHub
parent d53744187f
commit 1c23c5f2b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -260,9 +260,14 @@ const assignCurrentUserEmail = assign( {
const assignOnboardingProfile = assign( {
onboardingProfile: ( {
event,
context,
}: {
event: DoneActorEvent< OnboardingProfile | undefined >;
} ) => event.output,
context: CoreProfilerStateMachineContext;
} ) =>
! event.output || typeof event.output !== 'object'
? context.onboardingProfile // if the onboarding profile is not an object, keep the existing context
: event.output,
} );
const getGeolocation = fromPromise(

View File

@ -124,12 +124,12 @@ export const BusinessInfo = ( {
businessInfo,
countries,
onboardingProfile: {
is_store_country_set: isStoreCountrySet,
industry: industryFromOnboardingProfile,
business_choice: businessChoiceFromOnboardingProfile,
is_agree_marketing: isOptInMarketingFromOnboardingProfile,
store_email: storeEmailAddressFromOnboardingProfile,
},
is_store_country_set: isStoreCountrySet = false,
industry: industryFromOnboardingProfile = [],
business_choice: businessChoiceFromOnboardingProfile = '',
is_agree_marketing: isOptInMarketingFromOnboardingProfile = false,
store_email: storeEmailAddressFromOnboardingProfile = '',
} = {},
currentUserEmail,
} = context;

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Failure to fetch the country list no longer blocks users in the profiler.