From 774526221cac66f0cde2e6d1e04b1ce28e57802f Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Mon, 1 Dec 2025 07:59:30 -0500 Subject: [PATCH] feat: add explicit event handler for network analysis loading to improve reliability on initial page visits --- .../Servers/Proxmox/Livewire/Statistics.php | 14 ++++++ .../Proxmox/views/statistics.blade.php | 48 ++++++------------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/extensions/Servers/Proxmox/Livewire/Statistics.php b/extensions/Servers/Proxmox/Livewire/Statistics.php index 7d1d99e2e..32a4a2b65 100644 --- a/extensions/Servers/Proxmox/Livewire/Statistics.php +++ b/extensions/Servers/Proxmox/Livewire/Statistics.php @@ -150,6 +150,20 @@ class Statistics extends Component $this->fetchGraphData('disk', $this->diskTimeRange, $this->diskAggregation); } + /** + * Explicit event handler for Network Analysis lazy loading. + * + * This mirrors the Live Telemetry pattern (proxmox:stats) and allows the + * frontend to trigger loading via Livewire.dispatch(), which is more + * robust than relying on @this in inline scripts – especially on the + * first-ever load of the Statistics page for a given server. + */ + #[On('proxmox:network-analysis-load')] + public function handleNetworkAnalysisLoad(): void + { + $this->loadNetworkAnalysis(); + } + public function loadNetworkAnalysis(): void { Log::debug('Network Analysis: loadNetworkAnalysis() called', [ diff --git a/extensions/Servers/Proxmox/views/statistics.blade.php b/extensions/Servers/Proxmox/views/statistics.blade.php index 6df1e1f3f..e896bd8c5 100644 --- a/extensions/Servers/Proxmox/views/statistics.blade.php +++ b/extensions/Servers/Proxmox/views/statistics.blade.php @@ -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); }