feat: add explicit event handler for network analysis loading to improve reliability on initial page visits

This commit is contained in:
2025-12-01 07:59:30 -05:00
parent 7307ea9343
commit 774526221c
2 changed files with 28 additions and 34 deletions

View File

@@ -4467,41 +4467,22 @@
// Initialize charts
initializeCharts();
// Robust helper to invoke the Livewire Network Analysis load, with retries
function invokeNetworkAnalysisLoad(attempt) {
var maxAttempts = 5;
var currentAttempt = attempt || 1;
var delay = Math.min(500 * currentAttempt, 3000); // gradual backoff, capped
try {
if (typeof @this !== 'undefined' && @this.call) {
@this.call('loadNetworkAnalysis');
console.log('Network Analysis load request sent to server (attempt ' + currentAttempt + ')');
} else {
throw new Error('Livewire @this is not available yet');
}
} catch (e) {
console.warn('Failed to load Network Analysis on attempt ' + currentAttempt + ':', e);
// Retry a few times in case Livewire is not fully booted yet on first paint
if (currentAttempt < maxAttempts) {
setTimeout(function() {
invokeNetworkAnalysisLoad(currentAttempt + 1);
}, delay);
}
}
}
// Load Network Analysis after charts are initialized (non-blocking)
function loadNetworkAnalysisData() {
// Start the timeout FIRST before loading, so it's guaranteed to start
console.log('Starting Network Analysis load process - timeout will begin');
startNetworkAnalysisTimeout();
// Give the page a brief moment to finish initial layout,
// then attempt to call the Livewire method with automatic retries.
setTimeout(function() {
invokeNetworkAnalysisLoad(1);
try {
// Use a Livewire event instead of @this directly so that
// the initial load is reliable even on first-ever visits.
Livewire.dispatch('proxmox:network-analysis-load');
console.log('Network Analysis load event dispatched');
} catch (e) {
console.warn('Failed to dispatch Network Analysis load event:', e);
// Even if dispatch fails, timeout is already started
}
}, 500);
}
@@ -4672,11 +4653,10 @@
setTimeout(function() {
try {
if (typeof @this !== 'undefined' && @this.call) {
@this.call('loadNetworkAnalysis');
} else {
console.error('Livewire component not available for retry');
}
// Dispatch the same event used for initial load so that
// retries are decoupled from any specific @this instance.
Livewire.dispatch('proxmox:network-analysis-load');
console.log('Network Analysis retry event dispatched after 502 (delay ' + delay + 'ms)');
} catch (e) {
console.error('Failed to retry Network Analysis after 502 error:', e);
}