Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(traffic): show empty-state when all dashboard analytics fetches fail

Aditya Tripathid1f6fd49068d
diff --git a/app/Livewire/Dashboard/TrafficAnalytics.php b/app/Livewire/Dashboard/TrafficAnalytics.php
index 409c96a982..5270644582 100644
--- a/app/Livewire/Dashboard/TrafficAnalytics.php
+++ b/app/Livewire/Dashboard/TrafficAnalytics.php
@@ -91,6 +91,17 @@ class TrafficAnalytics extends Component
}
}
+ if (empty($overviews)) {
+ // Every server's fetch failed; don't present an all-zero KPI panel as if it were real data.
+ $this->overview = null;
+ $this->latencyApproximate = false;
+ $this->uniquesApproximate = false;
+ $this->topApps = [];
+ $this->topCountries = [];
+
+ return;
+ }
+
$result = TrafficAnalyticsAggregator::sumOverviews($overviews);
$this->overview = $result['overview']->toArray();
diff --git a/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php b/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php
index 660d0e3a23..777d2411db 100644
--- a/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php
+++ b/tests/Feature/TrafficAnalytics/DashboardTrafficAnalyticsTest.php
@@ -27,6 +27,14 @@ class FakeDashboardTrafficClient extends SentinelTrafficClient
}
}
+class FailingDashboardTrafficClient extends SentinelTrafficClient
+{
+ protected function raw(string $url): string
+ {
+ throw new RuntimeException('Server unreachable');
+ }
+}
+
function fakeDashboardTrafficResponses(int $requests = 1000): array
{
return [
@@ -100,6 +108,32 @@ it('renders the team traffic summary aggregated across servers with an approxima
->assertSee('approximate');
});
+it('shows a failure empty-state instead of an all-zero KPI panel when every server fetch fails', function () {
+ $serverOne = Server::factory()->create([
+ 'team_id' => $this->team->id,
+ 'private_key_id' => $this->privateKey->id,
+ ]);
+ $serverOne->settings->is_traffic_analytics_enabled = true;
+ $serverOne->settings->save();
+
+ $serverTwo = Server::factory()->create([
+ 'team_id' => $this->team->id,
+ 'private_key_id' => $this->privateKey->id,
+ ]);
+ $serverTwo->settings->is_traffic_analytics_enabled = true;
+ $serverTwo->settings->save();
+
+ app()->bind(SentinelTrafficClient::class, function ($app, $params) {
+ return new FailingDashboardTrafficClient($params['server']);
+ });
+
+ Livewire::test(TrafficAnalytics::class)
+ ->assertOk()
+ ->assertSee('No analytics data yet')
+ ->assertDontSee('Unique visitors')
+ ->assertDontSee('Error rate');
+});
+
it('shows an empty state when no server in the team has traffic analytics enabled', function () {
Server::factory()->create([
'team_id' => $this->team->id,