11import { ReactElement } from "react" ;
22
3- import type { GetServerSideProps } from "next" ;
3+ import type { GetStaticPaths , GetStaticProps } from "next" ;
44
55import { CampaignLayout } from "@/layout/campaign/components/layout" ;
66import { RootLayout } from "@/layout/components/root-layout" ;
@@ -41,8 +41,17 @@ const stripHtmlTags = (html: string | undefined | null): string => {
4141 return html . replace ( / < [ ^ > ] * > / g, "" ) . trim ( ) ;
4242} ;
4343
44- // SSR - fetch campaign data on every request
45- export const getServerSideProps : GetServerSideProps < PageProps > = async ( { params, res } ) => {
44+ // ISR: No build-time pre-generation to prevent timeouts
45+ // All pages generated on-demand when first requested, then cached
46+ export const getStaticPaths : GetStaticPaths = async ( ) => {
47+ return {
48+ paths : [ ] , // No pre-generation at build time
49+ fallback : "blocking" , // Generate on first visit, then cache with ISR
50+ } ;
51+ } ;
52+
53+ // ISR: Fetch campiagn data and cache with 2-minute revalidation
54+ export const getStaticProps : GetStaticProps < PageProps > = async ( { params } ) => {
4655 const campaignId = params ?. campaignId as string ;
4756
4857 if ( ! campaignId || isNaN ( Number ( campaignId ) ) ) {
@@ -51,12 +60,9 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async ({ params
5160
5261 const numericCampaignId = parseInt ( campaignId , 10 ) ;
5362
54- // Set cache headers - cache for 5 minutes, stale-while-revalidate for 10 minutes
55- res . setHeader ( "Cache-Control" , "public, s-maxage=300, stale-while-revalidate=600" ) ;
56-
5763 try {
5864 const controller = new AbortController ( ) ;
59- const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 5000 ) ;
65+ const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 8000 ) ;
6066
6167 const response = await fetch (
6268 `https://dev.potlock.io/api/v1/campaigns/${ encodeURIComponent ( campaignId ) } ` ,
@@ -77,6 +83,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async ({ params
7783 seoDescription : DEFAULT_SEO . description ,
7884 seoImage : DEFAULT_SEO . image ,
7985 } ,
86+ revalidate : 60 , // Retry sooner on error
8087 } ;
8188 }
8289
@@ -89,6 +96,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async ({ params
8996 seoDescription : stripHtmlTags ( campaign ?. description ) || DEFAULT_SEO . description ,
9097 seoImage : campaign ?. cover_image_url || DEFAULT_SEO . image ,
9198 } ,
99+ revalidate : 120 , // Revalidate every 2 minutes
92100 } ;
93101 } catch ( error ) {
94102 console . error ( `Error fetching campaign ${ campaignId } :` , error ) ;
@@ -100,6 +108,7 @@ export const getServerSideProps: GetServerSideProps<PageProps> = async ({ params
100108 seoDescription : DEFAULT_SEO . description ,
101109 seoImage : DEFAULT_SEO . image ,
102110 } ,
111+ revalidate : 60 , // Retry sooner on error
103112 } ;
104113 }
105114} ;
0 commit comments