Skip to content

Commit c5a64ad

Browse files
cj-vanaclaude
andcommitted
fix: Add cache: 'no-store' to client-side fetches for real-time data
Prevents Next.js from caching API responses on the client side, ensuring live stats load immediately without needing page refresh. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 81fa110 commit c5a64ad

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/components/NetworkHealthCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function NetworkHealthCard({ refreshInterval = 30000 }: NetworkHealthCard
4545

4646
const fetchHealth = useCallback(async () => {
4747
try {
48-
const res = await fetch('/api/health');
48+
const res = await fetch('/api/health', { cache: 'no-store' });
4949
const data: ApiResponse<NetworkHealth> = await res.json();
5050

5151
if (!data.success) {

src/components/NetworkMap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function NetworkMap({ nodes, className = '' }: NetworkMapProps) {
7474

7575
async function fetchNodes() {
7676
try {
77-
const res = await fetch('/api/nodes');
77+
const res = await fetch('/api/nodes', { cache: 'no-store' });
7878
const data = await res.json();
7979
if (data.success && data.data) {
8080
setMapNodes(data.data);

src/hooks/useStats.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export function useStats(options: UseStatsOptions = {}): UseStatsReturn {
3636
const fetchData = useCallback(async () => {
3737
try {
3838
if (includeHealth) {
39-
// Fetch both stats and health in parallel
39+
// Fetch both stats and health in parallel (no cache for real-time data)
4040
const [statsRes, healthRes] = await Promise.all([
41-
fetch('/api/stats'),
42-
fetch('/api/health'),
41+
fetch('/api/stats', { cache: 'no-store' }),
42+
fetch('/api/health', { cache: 'no-store' }),
4343
]);
4444

4545
if (!statsRes.ok) {
@@ -74,8 +74,8 @@ export function useStats(options: UseStatsOptions = {}): UseStatsReturn {
7474
setStats(statsData.data ?? null);
7575
setHealth(healthData.data ?? null);
7676
} else {
77-
// Fetch only stats
78-
const res = await fetch('/api/stats');
77+
// Fetch only stats (no cache for real-time data)
78+
const res = await fetch('/api/stats', { cache: 'no-store' });
7979

8080
if (!res.ok) {
8181
throw new Error(`Stats API returned ${res.status}`);

0 commit comments

Comments
 (0)