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:
@@ -31,6 +31,9 @@ class Spa {
|
|||||||
// Flag to prevent re-entrant dispatch
|
// Flag to prevent re-entrant dispatch
|
||||||
static is_dispatching = false;
|
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
|
* Framework module initialization hook called during framework boot
|
||||||
* Only runs when window.rsxapp.is_spa === true
|
* Only runs when window.rsxapp.is_spa === true
|
||||||
@@ -399,7 +402,10 @@ class Spa {
|
|||||||
*/
|
*/
|
||||||
static async dispatch(url, options = {}) {
|
static async dispatch(url, options = {}) {
|
||||||
if (Spa.is_dispatching) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,6 +633,18 @@ class Spa {
|
|||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
Spa.is_dispatching = false;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user