From 369a7e7edfe96210cb1972cac5476303a3296d91 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Fri, 15 May 2026 14:40:25 +0200 Subject: [PATCH] =?UTF-8?q?fix(scans):=20rafra=C3=AEchit=20l'historique=20?= =?UTF-8?q?et=20l'inventaire=20apr=C3=A8s=20un=20scan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'historique des scans ne se mettait pas à jour après un POST sur /api/discovery : le Server Component restait servi depuis le cache route de Next. - discovery-launcher : appelle router.refresh() après un scan réussi pour invalider le cache et re-rendre la page parent. - scans/page.tsx + hosts/page.tsx : déclare `dynamic = 'force-dynamic'` et `revalidate = 0`. Sans ça, Next pouvait statifier ces routes au build (mode standalone) puisque la fonction getX() ne fait pas appel à un signal dynamique. Co-Authored-By: Claude Opus 4.7 --- src/app/(dashboard)/hosts/page.tsx | 4 ++++ src/app/(dashboard)/scans/page.tsx | 4 ++++ src/components/scans/discovery-launcher.tsx | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/app/(dashboard)/hosts/page.tsx b/src/app/(dashboard)/hosts/page.tsx index 8ef218f..de51258 100644 --- a/src/app/(dashboard)/hosts/page.tsx +++ b/src/app/(dashboard)/hosts/page.tsx @@ -15,6 +15,10 @@ import { } from '@/components/ui/table'; import { prisma } from '@/lib/db/prisma'; +// L'inventaire évolue à chaque scan : pas de cache de route +export const dynamic = 'force-dynamic'; +export const revalidate = 0; + async function getHosts() { try { return await prisma.host.findMany({ diff --git a/src/app/(dashboard)/scans/page.tsx b/src/app/(dashboard)/scans/page.tsx index b728f33..a5e8bf3 100644 --- a/src/app/(dashboard)/scans/page.tsx +++ b/src/app/(dashboard)/scans/page.tsx @@ -15,6 +15,10 @@ import { import { DiscoveryLauncher } from '@/components/scans/discovery-launcher'; import { prisma } from '@/lib/db/prisma'; +// L'historique change à chaque scan : pas de cache de route +export const dynamic = 'force-dynamic'; +export const revalidate = 0; + async function getScans() { try { return await prisma.scan.findMany({ diff --git a/src/components/scans/discovery-launcher.tsx b/src/components/scans/discovery-launcher.tsx index 6d70a79..fbe0289 100644 --- a/src/components/scans/discovery-launcher.tsx +++ b/src/components/scans/discovery-launcher.tsx @@ -1,6 +1,7 @@ 'use client'; import { useState } from 'react'; +import { useRouter } from 'next/navigation'; import { Radar, Zap } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -10,6 +11,7 @@ import { Card } from '@/components/ui/card'; type Kind = 'full' | 'ping' | 'port' | 'arp' | 'mdns'; export function DiscoveryLauncher() { + const router = useRouter(); const [kind, setKind] = useState('full'); const [cidr, setCidr] = useState('192.168.1.0/24'); const [loading, setLoading] = useState(false); @@ -37,6 +39,8 @@ export function DiscoveryLauncher() { setMessage( `✓ Scan ${json.data.status} — ${json.data.hostsFound} hôtes, ${json.data.portsFound} ports`, ); + // Invalide le cache route pour que l'historique se rafraîchisse + router.refresh(); } catch (e) { setMessage(`✕ ${(e as Error).message}`); } finally {