From e689b8699373ec79910e73eb85d4535e61fea217 Mon Sep 17 00:00:00 2001 From: janrembold Date: Mon, 22 Apr 2024 13:58:48 +0200 Subject: [PATCH] fix: possible race condition while loading topic data --- .../components/registration/Registration.tsx | 5 ++++- src/globalState/provider/RegistrationProvider.tsx | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/extensions/components/registration/Registration.tsx b/src/extensions/components/registration/Registration.tsx index 6122531b6..58fc3e5f5 100644 --- a/src/extensions/components/registration/Registration.tsx +++ b/src/extensions/components/registration/Registration.tsx @@ -79,7 +79,8 @@ export const Registration = () => { disabledNextButton, updateRegistrationData, registrationData, - availableSteps + availableSteps, + loading } = useContext(RegistrationContext); const { consultant: preselectedConsultant } = useContext(UrlParamsContext); const { tenant } = useContext(TenantContext); @@ -235,6 +236,8 @@ export const Registration = () => { [availableSteps, path, topicSlug] ); + if (loading) return null; + return ( <> ) { const { url } = useRouteMatch(); + const [loading, setLoading] = useState(true); const [disabledNextButton, setDisabledNextButton] = useState(true); const [hasTopicError, setHasTopicError] = useState(false); const [hasAgencyError, setHasAgencyError] = useState(false); @@ -144,6 +146,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { (async () => { const registrationData = getSessionStorageData() as RegistrationData; + if (registrationData.mainTopicId) { registrationData.mainTopic = await apiGetTopicById( registrationData.mainTopicId @@ -161,6 +164,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { ); } setRegistrationData(registrationData); + setLoading(false); })(); }, []); @@ -237,7 +241,8 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { availableSteps, hasConsultantError, hasAgencyError, - hasTopicError + hasTopicError, + loading }), [ availableSteps, @@ -246,7 +251,8 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { hasConsultantError, hasTopicError, registrationData, - updateRegistrationData + updateRegistrationData, + loading ] );