getStaticProps
ThegetStaticProps function fetches data at build time and passes it as props to the page component.
Basic Example
src/pages/index.tsx:225-256
With Parameters
For dynamic routes, parameters are available in the context:src/pages/anime/[animeSlug]/index.tsx:191-227
Incremental Static Regeneration
Pages include arevalidate property to enable ISR:
- Pages are generated at build time
- After 1 hour, the next request triggers a background regeneration
- Stale content is served while regeneration happens
- New content is available for subsequent requests
getStaticPaths
For dynamic routes,getStaticPaths specifies which paths to pre-render at build time.
Basic Implementation
src/pages/anime/[animeSlug]/index.tsx:229-249
Build-Time Caching
Notice thebuildTimeCache pattern:
src/pages/anime/[animeSlug]/index.tsx:189
This cache is populated during getStaticPaths and reused in getStaticProps to avoid redundant API calls:
src/pages/anime/[animeSlug]/index.tsx:192-193
MINIMAL_BUILD Mode
The project supports a minimal build mode for faster development builds.The fetchStaticPaths Helper
src/utils/fetchStaticPaths.ts:1-25
How It Works
- Development mode: Returns empty paths array, all pages generated on-demand
- MINIMAL_BUILD=true: Same behavior as development
- Production build: Pre-generates all paths
- Fallback: Always set to
"blocking"for on-demand generation of missing paths
Enabling MINIMAL_BUILD
Set the environment variable:src/utils/config.ts:10
staticPageGenerationTimeout
The Next.js config includes an extended timeout for static page generation:next.config.ts:25-31
Why These Settings?
- staticPageGenerationTimeout: Extended to 3600 seconds (1 hour) to handle large builds
- workerThreads: false: Disables multi-threading to preserve build-time cache between pages
- cpus: 1: Single-threaded builds ensure the
buildTimeCacheworks correctly
Shared Page Props
All pages include shared props for tracking and debugging:lastBuildAt: Timestamp of when the page was builtapiRequests: Number of API requests made during build
PageRevalidation component.
Handling 404s
When data doesn’t exist, returnnotFound:
Best Practices
- Use build-time caching to avoid redundant API calls between
getStaticPathsandgetStaticProps - Set appropriate revalidate times (3600 seconds = 1 hour is the standard)
- Always use fallback: “blocking” to handle new content after build
- Handle missing data by returning
notFound: true - Use MINIMAL_BUILD for faster development iterations
- Single-threaded builds ensure cache consistency across page generation