From 7502c9c67442418ba844bd9ae61f74bd3888f848 Mon Sep 17 00:00:00 2001 From: DavidHerran Date: Wed, 6 May 2026 14:39:57 -0500 Subject: [PATCH] feat: generateStaticParams for application + news slug pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pre-render all known slugs at build time so first visits are instant from cache. New slugs added after deploy render on-demand and get cached by ISR (revalidate=60). try/catch ensures the build never fails if the DB is unreachable during docker build — pages just fall back to on-demand rendering. Co-Authored-By: Claude Opus 4.6 --- src/app/[locale]/applications/[slug]/page.tsx | 17 ++++++++++++++--- src/app/[locale]/news/[slug]/page.tsx | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app/[locale]/applications/[slug]/page.tsx b/src/app/[locale]/applications/[slug]/page.tsx index 730593d..27a2e76 100644 --- a/src/app/[locale]/applications/[slug]/page.tsx +++ b/src/app/[locale]/applications/[slug]/page.tsx @@ -83,9 +83,20 @@ export async function generateMetadata({ } } -// generateStaticParams omitted — slug pages render on-demand and are cached -// by ISR (revalidate=60). The DYNAMIC_SERVER_USAGE issue that previously -// blocked this is now fixed via setRequestLocale. +// Pre-render all known application slugs at build time. New slugs added +// after deploy render on-demand and get cached by ISR (revalidate=60). +// try/catch ensures the build never fails if the DB is unreachable +// during docker build — pages just render on first request instead. +export async function generateStaticParams() { + try { + const apps = await prisma.application.findMany({ + select: { slug: true }, + }); + return apps.map((app) => ({ slug: app.slug })); + } catch { + return []; + } +} // 🔥 AHORA RECIBIMOS EL LOCALE DESDE LA URL export default async function ApplicationPage({ params }: { params: Promise<{ slug: string, locale: string }> }) { diff --git a/src/app/[locale]/news/[slug]/page.tsx b/src/app/[locale]/news/[slug]/page.tsx index 36f9fe3..9444c7c 100644 --- a/src/app/[locale]/news/[slug]/page.tsx +++ b/src/app/[locale]/news/[slug]/page.tsx @@ -48,9 +48,20 @@ export async function generateMetadata({ } } -// generateStaticParams omitted — slug pages render on-demand and are cached -// by ISR (revalidate=60). The DYNAMIC_SERVER_USAGE issue is fixed via -// setRequestLocale. +// Pre-render all published news slugs at build time. New articles added +// after deploy render on-demand and get cached by ISR (revalidate=60). +// try/catch ensures the build never fails if the DB is unreachable. +export async function generateStaticParams() { + try { + const articles = await prisma.newsArticle.findMany({ + where: { isActive: true }, + select: { slug: true }, + }); + return articles.map((a) => ({ slug: a.slug })); + } catch { + return []; + } +} // ── SÚPER PARSER MARKDOWN (Con Tablas, Imágenes y Dark/Light Mode) ── // ... (El código del Súper Parser se queda IGUAL, no te preocupes) ...