🐛 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:
parent
1ed89cbbad
commit
1f42910c55
2 changed files with 16 additions and 9 deletions
|
|
@ -113,16 +113,18 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshFlows() {
|
function refreshFlows() {
|
||||||
getTabsDataFromDB().then((DbData) => {
|
setTimeout(() => {
|
||||||
if (DbData && Object.keys(templates).length > 0) {
|
getTabsDataFromDB().then((DbData) => {
|
||||||
try {
|
if (DbData && Object.keys(templates).length > 0) {
|
||||||
processDBData(DbData);
|
try {
|
||||||
updateStateWithDbData(DbData);
|
processDBData(DbData);
|
||||||
} catch (e) {
|
updateStateWithDbData(DbData);
|
||||||
console.error(e);
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
||||||
const { setLoading } = useContext(alertContext);
|
const { setLoading } = useContext(alertContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
|
||||||
// We will keep a flag to handle the case where the component is unmounted before the API call resolves.
|
// We will keep a flag to handle the case where the component is unmounted before the API call resolves.
|
||||||
let isMounted = true;
|
let isMounted = true;
|
||||||
|
|
||||||
|
|
@ -85,6 +88,8 @@ export function TypesProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
getTypes();
|
getTypes();
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function deleteNode(idx: string) {
|
function deleteNode(idx: string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue