Fix Nav tab infinite recursion (pre-UX-sweep bug)

The reverted code had two bugs in the tab switching logic:
1. closeNavigate() called switchTab() -> infinite recursion since
   switchTab() calls closeNavigate() when leaving tabNavigate
2. currentTab was updated AFTER closeNavigate(), so the recursive
   call hit the same condition over and over

Fix: move currentTab assignment before cleanup, use a wasNavigating
flag to track the old tab state, and make closeNavigate() only reset
nav UI (caller handles tab transition).
This commit is contained in:
2026-05-21 07:45:16 -04:00
parent 62016bae83
commit 14687e7ba6
3 changed files with 15 additions and 6 deletions
+15 -6
View File
@@ -2339,15 +2339,19 @@
// TAB SWITCHING
// =========================================================================
function switchTab(tabId) {
const wasNavigating = AppState.currentTab === 'tabNavigate';
// Track previous tab for back navigation
if (AppState.currentTab !== tabId && AppState.currentTab !== 'tabNavigate') {
if (AppState.currentTab !== tabId && !wasNavigating) {
AppState._prevTab = AppState.currentTab;
}
// Cleanup nav page when leaving
if (AppState.currentTab === 'tabNavigate' && tabId !== 'tabNavigate') {
// Update current tab BEFORE cleanup to prevent recursion
// when closeNavigate() calls switchTab()
AppState.currentTab = tabId;
// Cleanup nav page when leaving (closeNavigate only resets nav state,
// it does NOT switch panels — we must NOT return early here)
if (wasNavigating && tabId !== 'tabNavigate') {
closeNavigate();
}
AppState.currentTab = tabId;
// Update tab panels
document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
@@ -3681,8 +3685,13 @@
function closeNavigate() {
if (navMap) { navMap.remove(); navMap = null; }
AppState._navData = null;
// Go back to previous tab or asset list
switchTab(AppState._prevTab || 'tabAssets');
// Reset navigate tab UI — does NOT switch tabs, caller handles that
const infoCard = document.getElementById('navInfoCard');
if (infoCard) infoCard.style.display = 'none';
const directionsCard = document.getElementById('navDirectionsCard');
if (directionsCard) directionsCard.style.display = 'none';
const gmapsLink = document.getElementById('navGoogleMapsLink');
if (gmapsLink) gmapsLink.style.display = 'none';
}
function clearRouteLine() {