Fix login redirect loop on optional asset load failure

This commit is contained in:
2026-02-21 12:30:03 +01:00
parent a0926fcd1a
commit 71e4d48d76

View File

@@ -27,14 +27,15 @@
{ href: 'daily-bookmarks.css', id: 'dailyBookmarksCss', disabled: true } { href: 'daily-bookmarks.css', id: 'dailyBookmarksCss', disabled: true }
]; ];
const jsFiles = [ const jsFiles = [
'app.js', { src: 'app.js' },
'dashboard.js', { src: 'dashboard.js' },
'settings.js', { src: 'settings.js' },
'ai-debug.js', { src: 'ai-debug.js' },
'vendor/list.min.js', { src: 'vendor/list.min.js' },
'automation.js', { src: 'automation.js' },
'daily-bookmarks.js', { src: 'daily-bookmarks.js' },
'trade-fairs.js' // Optional: new bookmark subpage. If not yet deployed/cached, app must still boot.
{ src: 'trade-fairs.js', optional: true }
]; ];
function withVersion(value) { function withVersion(value) {
@@ -65,16 +66,51 @@
}); });
} }
function normalizeScriptEntry(entry) {
if (typeof entry === 'string') {
return { src: entry, optional: false };
}
return {
src: entry && entry.src ? entry.src : '',
optional: Boolean(entry && entry.optional)
};
}
function showBootstrapError(message) {
document.body.classList.remove('auth-pending');
const loadingEl = document.getElementById('loading');
const errorEl = document.getElementById('error');
if (loadingEl) {
loadingEl.style.display = 'none';
}
if (errorEl) {
errorEl.style.display = 'block';
errorEl.textContent = message || 'Die Anwendung konnte nicht geladen werden.';
}
}
function loadScriptsSequentially(list, index = 0) { function loadScriptsSequentially(list, index = 0) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (index >= list.length) { if (index >= list.length) {
resolve(); resolve();
return; return;
} }
const entry = normalizeScriptEntry(list[index]);
if (!entry.src) {
loadScriptsSequentially(list, index + 1).then(resolve).catch(reject);
return;
}
const script = document.createElement('script'); const script = document.createElement('script');
script.src = withVersion(list[index]); script.src = withVersion(entry.src);
script.onload = () => loadScriptsSequentially(list, index + 1).then(resolve).catch(reject); script.onload = () => loadScriptsSequentially(list, index + 1).then(resolve).catch(reject);
script.onerror = reject; script.onerror = () => {
if (entry.optional) {
console.warn('Optionales Script konnte nicht geladen werden:', entry.src);
loadScriptsSequentially(list, index + 1).then(resolve).catch(reject);
return;
}
reject(new Error(`Script konnte nicht geladen werden: ${entry.src}`));
};
document.body.appendChild(script); document.body.appendChild(script);
}); });
} }
@@ -86,10 +122,14 @@
redirectToLogin(); redirectToLogin();
return; return;
} }
if (!res.ok) {
throw new Error(`Session-Check fehlgeschlagen (${res.status})`);
}
loadStyles(); loadStyles();
await loadScriptsSequentially(jsFiles); await loadScriptsSequentially(jsFiles);
} catch (_error) { } catch (error) {
redirectToLogin(); console.error('Bootstrap fehlgeschlagen:', error);
showBootstrapError('Fehler beim Laden der Anwendung. Bitte Seite neu laden.');
} }
} }