🐛 fix(tabsContext.tsx): add delay to refreshFlows function to prevent race condition with API call

🐛 fix(typesContext.tsx): add delay to useEffect to prevent race condition with API call
This commit is contained in:
Cristhian Zanforlin Lousa 2023-08-25 17:54:37 -03:00
commit 1f42910c55
2 changed files with 16 additions and 9 deletions

View file

@ -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(() => {

View file

@ -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) {