fix: sync ROUTE_ORDER with nav order, guard against navigation race condition

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ulas
2026-03-30 17:11:53 +02:00
parent bc3f855fa9
commit 20792e9894
+11 -1
View File
@@ -80,12 +80,13 @@ async function importPage(pagePath) {
// --------------------------------------------------------
let currentUser = null;
let currentPath = null;
let isNavigating = false;
// --------------------------------------------------------
// Router
// --------------------------------------------------------
const ROUTE_ORDER = ['/', '/tasks', '/shopping', '/meals', '/calendar',
const ROUTE_ORDER = ['/', '/tasks', '/calendar', '/meals', '/shopping',
'/notes', '/contacts', '/budget', '/settings'];
function getDirection(fromPath, toPath) {
@@ -103,6 +104,10 @@ function getDirection(fromPath, toPath) {
* @param {boolean} pushState - false beim initialen Load und popstate
*/
async function navigate(path, userOrPushState = true, pushState = true) {
if (isNavigating) return;
isNavigating = true;
try {
// Überlastung: navigate(path, user) nach Login vs navigate(path, false) beim Init
if (typeof userOrPushState === 'object' && userOrPushState !== null) {
currentUser = userOrPushState;
@@ -123,6 +128,7 @@ async function navigate(path, userOrPushState = true, pushState = true) {
currentUser = result.user;
} catch {
currentPath = null; // Reset damit navigate('/login') nicht geblockt wird
isNavigating = false;
navigate('/login');
return;
}
@@ -130,6 +136,7 @@ async function navigate(path, userOrPushState = true, pushState = true) {
if (!route.requiresAuth && currentUser && path === '/login') {
currentPath = null;
isNavigating = false;
navigate('/');
return;
}
@@ -141,6 +148,9 @@ async function navigate(path, userOrPushState = true, pushState = true) {
await renderPage(route, previousPath);
updateNav(path);
updateThemeColorForRoute(route);
} finally {
isNavigating = false;
}
}
/**