fix(v1.108.13): add comprehensive race condition guards in load.js

Add typeof checks for all function calls to modules loaded with defer attribute.
This prevents ReferenceError when loading old maps (1.108.11) in version 1.108.13.

Functions protected:
- getCurrentPreset() - from style.js
- addCustomColorScheme() - from style.js
- updateTextureSelectValue() - from style.js
- focusOn() - from editors.js
- invokeActiveZooming() - from zoom.js
- fitMapToScreen() - from zoom.js
- declareFont() - from fonts.js
- moveBurgToGroup() - from burgs.js (3 locations)

This fixes zoom/pan issues when loading old maps.
This commit is contained in:
Claude 2025-11-14 03:30:12 +00:00
parent 74b9310c57
commit 57b7980dbc
No known key found for this signature in database

View file

@ -280,7 +280,7 @@ async function parseLoadedData(data, mapVersion) {
family === usedFamily && unicodeRange === usedRange && variant === usedVariant
);
if (!defaultFont) fonts.push(usedFont);
declareFont(usedFont);
if (typeof declareFont !== "undefined") declareFont(usedFont);
});
}
}
@ -460,7 +460,7 @@ async function parseLoadedData(data, mapVersion) {
if (isVisible(scaleBar)) turnOn("toggleScaleBar");
if (isVisibleNode(byId("vignette"))) turnOn("toggleVignette");
getCurrentPreset();
if (typeof getCurrentPreset !== "undefined") getCurrentPreset();
}
{
@ -477,7 +477,7 @@ async function parseLoadedData(data, mapVersion) {
}
// add custom heightmap color scheme if any
if (typeof heightmapColorSchemes !== "undefined" && heightmapColorSchemes) {
if (typeof heightmapColorSchemes !== "undefined" && heightmapColorSchemes && typeof addCustomColorScheme !== "undefined") {
const oceanScheme = byId("oceanHeights")?.getAttribute("scheme");
if (oceanScheme && !(oceanScheme in heightmapColorSchemes)) addCustomColorScheme(oceanScheme);
const landScheme = byId("#landHeights")?.getAttribute("scheme");
@ -625,7 +625,7 @@ async function parseLoadedData(data, mapVersion) {
capitalBurgs.forEach(burg => {
burg.capital = 0;
moveBurgToGroup(burg.i, "towns");
if (typeof moveBurgToGroup !== "undefined") moveBurgToGroup(burg.i, "towns");
});
return;
@ -640,7 +640,7 @@ async function parseLoadedData(data, mapVersion) {
capitalBurgs.forEach((burg, i) => {
if (!i) return;
burg.capital = 0;
moveBurgToGroup(burg.i, "towns");
if (typeof moveBurgToGroup !== "undefined") moveBurgToGroup(burg.i, "towns");
});
return;
@ -650,7 +650,7 @@ async function parseLoadedData(data, mapVersion) {
ERROR &&
console.error(`[Data integrity] State ${state.i} has no capital. Assigning the first burg as capital`);
stateBurgs[0].capital = 1;
moveBurgToGroup(stateBurgs[0].i, "cities");
if (typeof moveBurgToGroup !== "undefined") moveBurgToGroup(stateBurgs[0].i, "cities");
}
});
@ -731,9 +731,9 @@ async function parseLoadedData(data, mapVersion) {
{
if (window.restoreDefaultEvents) restoreDefaultEvents();
focusOn(); // based on searchParams focus on point, cell or burg
invokeActiveZooming();
fitMapToScreen();
if (typeof focusOn !== "undefined") focusOn(); // based on searchParams focus on point, cell or burg
if (typeof invokeActiveZooming !== "undefined") invokeActiveZooming();
if (typeof fitMapToScreen !== "undefined") fitMapToScreen();
}
WARN && console.warn(`TOTAL: ${rn((performance.now() - uploadMap.timeStart) / 1000, 2)}s`);