From 1f42910c553a261264e228aa15a6a39fc06a7da0 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 25 Aug 2023 17:54:37 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(tabsContext.tsx):=20add=20de?= =?UTF-8?q?lay=20to=20refreshFlows=20function=20to=20prevent=20race=20cond?= =?UTF-8?q?ition=20with=20API=20call=20=F0=9F=90=9B=20fix(typesContext.tsx?= =?UTF-8?q?):=20add=20delay=20to=20useEffect=20to=20prevent=20race=20condi?= =?UTF-8?q?tion=20with=20API=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/contexts/tabsContext.tsx | 20 +++++++++++--------- src/frontend/src/contexts/typesContext.tsx | 5 +++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 2e3334f5e..15b0edcb2 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -113,16 +113,18 @@ export function TabsProvider({ children }: { children: ReactNode }) { } function refreshFlows() { - getTabsDataFromDB().then((DbData) => { - if (DbData && Object.keys(templates).length > 0) { - try { - processDBData(DbData); - updateStateWithDbData(DbData); - } catch (e) { - console.error(e); + setTimeout(() => { + getTabsDataFromDB().then((DbData) => { + if (DbData && Object.keys(templates).length > 0) { + try { + processDBData(DbData); + updateStateWithDbData(DbData); + } catch (e) { + console.error(e); + } } - } - }); + }); + }, 2000); } useEffect(() => { diff --git a/src/frontend/src/contexts/typesContext.tsx b/src/frontend/src/contexts/typesContext.tsx index 1ff3609e0..d8d3ca3ca 100644 --- a/src/frontend/src/contexts/typesContext.tsx +++ b/src/frontend/src/contexts/typesContext.tsx @@ -39,6 +39,9 @@ export function TypesProvider({ children }: { children: ReactNode }) { const { setLoading } = useContext(alertContext); useEffect(() => { + + setTimeout(() => { + // We will keep a flag to handle the case where the component is unmounted before the API call resolves. let isMounted = true; @@ -85,6 +88,8 @@ export function TypesProvider({ children }: { children: ReactNode }) { } getTypes(); + }, 2000); + }, []); function deleteNode(idx: string) {