diff --git a/app/RSpade/Core/SPA/Spa.js b/app/RSpade/Core/SPA/Spa.js index 42d3523d9..c65a5d89d 100755 --- a/app/RSpade/Core/SPA/Spa.js +++ b/app/RSpade/Core/SPA/Spa.js @@ -31,6 +31,9 @@ class Spa { // Flag to prevent re-entrant dispatch static is_dispatching = false; + // Pending redirect that occurred during dispatch (e.g., in action on_load) + static pending_redirect = null; + /** * Framework module initialization hook called during framework boot * Only runs when window.rsxapp.is_spa === true @@ -399,7 +402,10 @@ class Spa { */ static async dispatch(url, options = {}) { if (Spa.is_dispatching) { - console.warn('Spa: Already dispatching, ignoring nested dispatch'); + // Already dispatching - queue this as a pending redirect + // This commonly happens when an action redirects in on_load() + console_debug('Spa', 'Nested dispatch detected, queuing pending redirect: ' + url); + Spa.pending_redirect = { url, options }; return; } @@ -627,6 +633,18 @@ class Spa { throw error; } finally { Spa.is_dispatching = false; + + // Check if a redirect was queued during this dispatch + if (Spa.pending_redirect) { + const redirect = Spa.pending_redirect; + Spa.pending_redirect = null; + + console_debug('Spa', 'Processing pending redirect: ' + redirect.url); + + // Execute the queued redirect immediately + // This will destroy the action that triggered the redirect + await Spa.dispatch(redirect.url, redirect.options); + } } }