Fix race condition when switching version while mods are loading (#972)

* Fix race condition when switching version while mods are loading

* add ts-node for webpack and update workflows
This commit is contained in:
Zagrios
2025-12-06 23:03:46 +01:00
committed by GitHub
parent 06bb2fe416
commit 58f8d8e243
8 changed files with 170 additions and 11 deletions
@@ -219,9 +219,10 @@ export const ModsSlide = forwardRef<ModsSlideRef, Props>(({ version, isActive, o
}), [version]);
useEffect(() => {
let isCancelled = false;
if(!isActive){
return noop();
return noop;
}
ensureDisclaimerAccepted().then(async canLoad => {
@@ -229,13 +230,30 @@ export const ModsSlide = forwardRef<ModsSlideRef, Props>(({ version, isActive, o
return onDisclamerDecline?.();
}
if (isCancelled) return;
const status = await modsManager.getModsGridStatus();
if (isCancelled) return;
setGridStatus(() => status);
loadMods();
if (status !== ModsGridStatus.OK) {
return;
}
modsManager.getVersionModsState(version).then(({ available, installed }) => {
if (isCancelled) return;
const defaultMods = installed?.length ? [] : available.filter(m => m.mod.category === BbmCategories.Core || m.mod.category === BbmCategories.Essential);
setModsAvailable(() => modsToCategoryMap(available));
setModsSelected(available.filter(m => m.mod.category === BbmCategories.Core || defaultMods.some(d => m.mod.name.toLowerCase() === d.mod.name.toLowerCase()) || installed.some(i => m.mod.id === i.mod.id)));
setModsInstalled(modsToCategoryMap(installed));
});
});
return () => {
isCancelled = true;
setMoreInfoMod(null);
setModsAvailable(null);
setModsInstalled(null);