From 8f14774c5e04a3a13fccb890e9be7650e29b12aa Mon Sep 17 00:00:00 2001 From: rjchow Date: Fri, 12 May 2023 18:12:32 +1000 Subject: [PATCH] added prefetch for getCountries as well --- .../client/core-profiler/index.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/client/core-profiler/index.tsx b/plugins/woocommerce-admin/client/core-profiler/index.tsx index 302a857b82a6..0e05136786fa 100644 --- a/plugins/woocommerce-admin/client/core-profiler/index.tsx +++ b/plugins/woocommerce-admin/client/core-profiler/index.tsx @@ -106,6 +106,17 @@ const handleTrackingOption = assign( { ) => event.data !== 'no', } ); +/** + * Prefetch it so that @wp/data caches it and there won't be a loading delay when its used + */ +const preFetchGetCountries = assign( { + spawnGetCountriesRef: () => + spawn( + resolveSelect( COUNTRIES_STORE_NAME ).getCountries(), + 'core-profiler-prefetch-countries' + ), +} ); + const getCountries = async () => resolveSelect( COUNTRIES_STORE_NAME ).getCountries(); @@ -221,6 +232,7 @@ const handleExtensions = assign( { const coreProfilerMachineActions = { updateTrackingOption, preFetchGetExtensions, + preFetchGetCountries, handleTrackingOption, handleExtensions, recordTracksIntroCompleted, @@ -261,7 +273,7 @@ export const coreProfilerStateMachineDefinition = createMachine( { target: 'introOptIn', }, }, - entry: [ 'preFetchGetExtensions' ], + entry: [ 'preFetchGetExtensions', 'preFetchGetCountries' ], invoke: [ { src: 'getAllowTrackingOption',