Static and server-side props
What you need to know
getStaticProps prepares serializable page props for static generation, while getServerSideProps prepares them at request time. Choose according to freshness, access and operational requirements.
By the end, you can: compare getStaticProps and getServerSideProps; identify serialization boundaries.
Generate a public catalog snapshot
// pages/catalog/index.tsximport type { GetStaticProps, InferGetStaticPropsType } from 'next';export const getStaticProps = (async () => ({props:{titles:['Fern Atlas','River Walk']}, revalidate:120})) satisfies GetStaticProps<{titles:string[]}>;export default function Catalog({titles}: InferGetStaticPropsType<typeof getStaticProps>) { return <main><h1>Catalog</h1><ul>{titles.map(title=><li key={title}>{title}</li>)}</ul></main>;}Expected behavior: The public list is eligible for static generation and later ISR. The 120-second threshold is not a promise of an update every two minutes.
How it works
Both functions are exported from Pages Router page modules and execute on the server. They return objects such as props, notFound or redirect according to their respective contracts. Static props can be generated during build or regeneration, and revalidate adds an ISR interval rather than scheduling an exact periodic job. Request-time props can read request-specific context and are appropriate for data that must be checked for each request. The browser receives serialized page props on direct loads or client transitions; never put tokens, internal notes or private fields in the returned object just because the function runs on the server. Use plain JSON-compatible data, converting dates explicitly and handling missing fields. A server-only data source is safe to call directly from the data function; there is generally no need to make an HTTP request to your own API route for the same process. Do not export both functions from one page. Automatic static optimization can apply when no blocking data function is used; inspect the actual build rather than guessing.
Read a benign preference at request time
// pages/view.tsximport type { GetServerSideProps, InferGetServerSidePropsType } from 'next';export const getServerSideProps = (async ({req,res}) => { res.setHeader('Cache-Control','private, no-store'); return {props:{view:req.cookies.view==='compact'?'compact':'comfortable'}};}) satisfies GetServerSideProps<{view:string}>;export default function View({view}:InferGetServerSidePropsType<typeof getServerSideProps>) {return <main><h1>View</h1><p>{view}</p></main>;}Expected behavior: Each request selects its display preference. The props contain only the selected public label, not the cookie jar.
Common mistake
Do not expose a server token in props, fetch personalized data during shared static generation, or use getServerSideProps solely to avoid learning cache requirements.
Practice and verification
Classify a public book list, inventory-at-checkout and visitor display preference. Record which data may be shared, which must be fresh, and what the browser receives. Test the direct and client data responses when the framework is available.
Scope: Proposed Next.js 16.x, React 19, Node runtime. Root-mounted Pages and mixed-router fixtures with Cache Components disabled; the basePath example is separate. Framework examples are staged, not executed. Exact patched dependencies and platform contracts pending.