Skip to content

Commit e609b10

Browse files
committed
fix: core profiler plugins list race condition
1 parent bd696c0 commit e609b10

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

plugins/woocommerce-admin/client/core-profiler/index.tsx

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ const updateOnboardingProfileOption = (
364364
} );
365365
};
366366

367+
const spawnUpdateOnboardingProfileOption = assign( {
368+
spawnUpdateOnboardingProfileOptionRef: (
369+
context: CoreProfilerStateMachineContext
370+
) =>
371+
spawn(
372+
() => updateOnboardingProfileOption( context ),
373+
'update-onboarding-profile'
374+
),
375+
} );
376+
367377
const updateBusinessLocation = ( countryAndState: string ) => {
368378
return dispatch( OPTIONS_STORE_NAME ).updateOptions( {
369379
woocommerce_default_country: countryAndState,
@@ -389,7 +399,7 @@ const assignUserProfile = assign( {
389399

390400
const updateBusinessInfo = async (
391401
_context: CoreProfilerStateMachineContext,
392-
event: BusinessInfoEvent
402+
event: AnyEventObject
393403
) => {
394404
const refreshedOnboardingProfile = ( await resolveSelect(
395405
OPTIONS_STORE_NAME
@@ -518,6 +528,7 @@ const coreProfilerMachineActions = {
518528
handleOnboardingProfileOption,
519529
assignOnboardingProfile,
520530
persistBusinessInfo,
531+
spawnUpdateOnboardingProfileOption,
521532
redirectToWooHome,
522533
};
523534

@@ -530,6 +541,7 @@ const coreProfilerMachineServices = {
530541
getOnboardingProfileOption,
531542
getPlugins,
532543
browserPopstateHandler,
544+
updateBusinessInfo,
533545
};
534546
export const coreProfilerStateMachineDefinition = createMachine( {
535547
id: 'coreProfiler',
@@ -772,16 +784,9 @@ export const coreProfilerStateMachineDefinition = createMachine( {
772784
] ),
773785
},
774786
postUserProfile: {
775-
invoke: {
776-
src: ( context ) => {
777-
return updateOnboardingProfileOption( context );
778-
},
779-
onDone: {
780-
target: '#businessInfo',
781-
},
782-
onError: {
783-
target: '#businessInfo',
784-
},
787+
entry: [ 'spawnUpdateOnboardingProfileOption' ],
788+
always: {
789+
target: '#businessInfo',
785790
},
786791
},
787792
},
@@ -938,11 +943,19 @@ export const coreProfilerStateMachineDefinition = createMachine( {
938943
],
939944
on: {
940945
BUSINESS_INFO_COMPLETED: {
946+
target: 'postBusinessInfo',
947+
actions: [ 'recordTracksBusinessInfoCompleted' ],
948+
},
949+
},
950+
},
951+
postBusinessInfo: {
952+
invoke: {
953+
src: 'updateBusinessInfo',
954+
onDone: {
955+
target: '#plugins',
956+
},
957+
onError: {
941958
target: '#plugins',
942-
actions: [
943-
'persistBusinessInfo',
944-
'recordTracksBusinessInfoCompleted',
945-
],
946959
},
947960
},
948961
},
@@ -1337,8 +1350,8 @@ export const CoreProfilerController = ( {
13371350
);
13381351

13391352
const navigationProgress = currentNodeMeta?.progress;
1340-
const CurrentComponent =
1341-
currentNodeMeta?.component ?? ( () => <ProfileSpinner /> ); // If no component is defined for the state then its a loading state
1353+
1354+
const CurrentComponent = currentNodeMeta?.component;
13421355

13431356
const currentNodeCssLabel =
13441357
state.value instanceof Object
@@ -1364,13 +1377,15 @@ export const CoreProfilerController = ( {
13641377
<div
13651378
className={ `woocommerce-profile-wizard__container woocommerce-profile-wizard__step-${ currentNodeCssLabel }` }
13661379
>
1367-
{
1380+
{ CurrentComponent ? (
13681381
<CurrentComponent
13691382
navigationProgress={ navigationProgress }
13701383
sendEvent={ send }
13711384
context={ state.context }
13721385
/>
1373-
}
1386+
) : (
1387+
<ProfileSpinner />
1388+
) }
13741389
</div>
13751390
</>
13761391
);

plugins/woocommerce-admin/client/core-profiler/pages/BusinessInfo.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const BusinessInfo = ( {
9191
onboardingProfile: {
9292
is_store_country_set: isStoreCountrySet,
9393
industry: industryFromOnboardingProfile,
94+
business_choice: businessChoiceFromOnboardingProfile,
9495
},
9596
} = context;
9697

@@ -152,7 +153,9 @@ export const BusinessInfo = ( {
152153
const selectCountryLabel = __( 'Select country/region', 'woocommerce' );
153154
const selectIndustryQuestionLabel =
154155
selectIndustryMapping[
155-
businessChoice || 'im_just_starting_my_business'
156+
businessChoice ||
157+
businessChoiceFromOnboardingProfile ||
158+
'im_just_starting_my_business'
156159
];
157160

158161
const [ dismissedGeolocationNotice, setDismissedGeolocationNotice ] =
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: tweak
3+
4+
Fixed race condition in core profiler's plugin list fetching and also minor spinner fixes

0 commit comments

Comments
 (0)