Convert Spa.action property to Spa.action() method

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-29 05:49:17 +00:00
parent 1b46c5270c
commit bded711d1c
5 changed files with 161 additions and 15 deletions

View File

@@ -19,8 +19,8 @@ class Spa {
// Current layout instance
static layout = null;
// Current action instance
static action = null;
// Current action instance (use Spa.action() to access)
static _action = null;
// Current route instance
static route = null;
@@ -49,6 +49,29 @@ class Spa {
// Grace period in milliseconds for suppressing errors after navigation
static NAVIGATION_GRACE_PERIOD_MS = 10000;
/**
* Get the current action component instance
*
* Returns the cached action if available, otherwise finds it from the DOM.
* This method should be used instead of direct property access to ensure
* the action is always found even if the cache was cleared.
*
* @returns {Spa_Action|null} The current action instance, or null if none
*/
static action() {
if (Spa._action) {
return Spa._action;
}
const $spa_action = $('.Spa_Action').first();
if (!$spa_action.exists()) {
return null;
}
Spa._action = $spa_action.component();
return Spa._action;
}
/**
* Check if we're within the navigation grace period
*
@@ -543,6 +566,9 @@ class Spa {
Spa.is_dispatching = true;
// Clear cached action - will be set when new action is created
Spa._action = null;
// Record navigation timestamp for error suppression grace period
// Errors from previous page's pending requests should be ignored for 10 seconds
Spa._navigation_timestamp = Date.now();
@@ -911,7 +937,7 @@ class Spa {
if (is_last) {
// This is the action - set reference but don't wait
Spa.action = component;
Spa._action = component;
} else {
// This is a layout
// Wait for render to complete (not full ready - we don't need child data to load)
@@ -932,7 +958,7 @@ class Spa {
for (const layout of layouts_for_on_action) {
// Set action reference before calling on_action so layouts can access it
layout.action = Spa.action;
layout.action = Spa.action();
if (layout.on_action) {
layout.on_action(url, action_name, args);
}