Allow SPA actions to redirect during loading phase

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-20 20:00:32 +00:00
parent ff77724e2b
commit c60cd84e57

View File

@@ -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);
}
}
}