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:
+11
-1
@@ -80,12 +80,13 @@ async function importPage(pagePath) {
|
|||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
let currentUser = null;
|
let currentUser = null;
|
||||||
let currentPath = null;
|
let currentPath = null;
|
||||||
|
let isNavigating = false;
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
// Router
|
// Router
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
|
|
||||||
const ROUTE_ORDER = ['/', '/tasks', '/shopping', '/meals', '/calendar',
|
const ROUTE_ORDER = ['/', '/tasks', '/calendar', '/meals', '/shopping',
|
||||||
'/notes', '/contacts', '/budget', '/settings'];
|
'/notes', '/contacts', '/budget', '/settings'];
|
||||||
|
|
||||||
function getDirection(fromPath, toPath) {
|
function getDirection(fromPath, toPath) {
|
||||||
@@ -103,6 +104,10 @@ function getDirection(fromPath, toPath) {
|
|||||||
* @param {boolean} pushState - false beim initialen Load und popstate
|
* @param {boolean} pushState - false beim initialen Load und popstate
|
||||||
*/
|
*/
|
||||||
async function navigate(path, userOrPushState = true, pushState = true) {
|
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
|
// Überlastung: navigate(path, user) nach Login vs navigate(path, false) beim Init
|
||||||
if (typeof userOrPushState === 'object' && userOrPushState !== null) {
|
if (typeof userOrPushState === 'object' && userOrPushState !== null) {
|
||||||
currentUser = userOrPushState;
|
currentUser = userOrPushState;
|
||||||
@@ -123,6 +128,7 @@ async function navigate(path, userOrPushState = true, pushState = true) {
|
|||||||
currentUser = result.user;
|
currentUser = result.user;
|
||||||
} catch {
|
} catch {
|
||||||
currentPath = null; // Reset damit navigate('/login') nicht geblockt wird
|
currentPath = null; // Reset damit navigate('/login') nicht geblockt wird
|
||||||
|
isNavigating = false;
|
||||||
navigate('/login');
|
navigate('/login');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -130,6 +136,7 @@ async function navigate(path, userOrPushState = true, pushState = true) {
|
|||||||
|
|
||||||
if (!route.requiresAuth && currentUser && path === '/login') {
|
if (!route.requiresAuth && currentUser && path === '/login') {
|
||||||
currentPath = null;
|
currentPath = null;
|
||||||
|
isNavigating = false;
|
||||||
navigate('/');
|
navigate('/');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -141,6 +148,9 @@ async function navigate(path, userOrPushState = true, pushState = true) {
|
|||||||
await renderPage(route, previousPath);
|
await renderPage(route, previousPath);
|
||||||
updateNav(path);
|
updateNav(path);
|
||||||
updateThemeColorForRoute(route);
|
updateThemeColorForRoute(route);
|
||||||
|
} finally {
|
||||||
|
isNavigating = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user