} The fully-loaded action instance, or null if route not found
*
* @example
* // Basic usage
* const action = await Spa.load_detached_action('/contacts/123');
* if (action) {
* const title = action.get_title?.() ?? action.constructor.name;
* console.log('Page title:', title);
* action.stop(); // Clean up when done
* }
*
* @example
* // With cached data (faster, no network request if cached)
* const action = await Spa.load_detached_action('/contacts/123', {use_cached_data: true});
*/
static async load_detached_action(url, extra_args = {}) {
// Parse URL and match to route
const parsed = Spa.parse_url(url);
const url_without_hash = parsed.path + parsed.search;
const route_match = Spa.match_url_to_route(url_without_hash);
if (!route_match) {
console_debug('Spa', 'load_detached_action: No route match for ' + url);
return null;
}
const action_class = route_match.action_class;
const action_name = action_class.name;
// Merge URL args with extra_args (extra_args take precedence)
const args = { ...route_match.args, ...extra_args };
console_debug('Spa', `load_detached_action: Loading ${action_name} with args:`, args);
// Create a detached container (not in DOM)
const $detached = $('');
// Instantiate the action on the detached element
// This triggers the full component lifecycle: on_create -> render -> on_render -> on_load -> on_ready
$detached.component(action_name, args);
const action = $detached.component();
// Wait for the action to be fully ready (including on_load completion)
await action.ready();
console_debug('Spa', `load_detached_action: ${action_name} ready`);
return action;
}
}