Using getStaticProps with CMS Data

In Brief
getStaticProps is useful for CMS‑backed Pages Router sites when the content is stable enough to generate ahead of time. It still needs careful field validation, clean page models, preview separation and a clear rebuild or ISR plan so editors understand when published content appears.
getStaticProps is a good fit for many content‑led Next.js Pages Router sites, but it is easy to overstate what it solves.
It fetches data at build time, renders HTML and serves that page statically. That can be fast and reliable for public content. It can also make publishing dependent on rebuilds, hide preview problems, over‑fetch CMS data or fail a deployment because one referenced entry is missing.
The mistake to avoid is choosing getStaticProps just because static pages are fast. Static generation is a rendering choice and an editorial workflow choice.
Start with the Page's Freshness Requirement
Before writing the data fetching code, decide how fresh the page needs to be.
Some CMS‑backed pages are stable:
- evergreen articles
- case studies
- service pages
- documentation pages
- landing pages with planned updates
Those are usually good candidates for static generation.
Other content needs immediate freshness:
- stock or availability data
- time‑sensitive pricing
- event status
- frequently changing listings
- logged‑in or personalised content
For that kind of content, getStaticProps may still be possible with Incremental Static Regeneration (ISR) or rebuild triggers, but it is no longer a simple "build once and forget" decision.
Fetch Only What the Page Needs
getStaticProps runs during static generation. That makes it a good place to fetch the content needed by one page.
For an article page, that might include:
- title
- slug
- body content
- author
- publish date
- SEO fields
- related entries
- image data
- category data
The related article on `getStaticProps` versus `getServerSideProps` covers the broader rendering choice. With CMS data, the practical habit is to keep the query specific enough that the page model is easy to understand.
Avoid passing a whole CMS response into a component and hoping the component knows what to do with it. Normalise the shape the page actually needs.
Validate CMS Assumptions Before Rendering
CMS data can be incomplete even when the content model looks strict.
Entries can be unpublished. References can be missing. Assets can lack dimensions. Slugs can collide. Rich text can contain embedded entries the renderer does not support. Scheduled content can create different results depending on when the build runs.
Check the fields that matter before rendering:
- title
- slug
- publish date
- body content
- required image fields
- referenced entries
- metadata fields
- canonical or SEO fields where used
If the page cannot be generated safely, fail with a useful message during the build rather than publishing broken HTML. A noisy build failure is better than a quiet production page with missing content.
Pair dynamic routes with getStaticPaths
For routes such as /articles/[slug], getStaticProps usually works with getStaticPaths.
getStaticPaths decides which paths should exist. getStaticProps fetches the data for each path.
In CMS work, this raises practical questions:
- should every published entry generate a page?
- what happens when an entry is unpublished?
- should draft or scheduled entries be excluded?
- do old slugs need redirects?
- should unknown paths return
404, use a fallback or wait for regeneration?
Those decisions affect crawlability, editor trust and deployment behaviour. They are not just implementation details.
Keep Preview Separate from Public Generation
Published pages and preview pages have different data needs.
A public static page should usually fetch published content only. A preview path may need draft entries, unpublished references or a different API token.
Do not blur those concerns. If preview code can fetch drafts, make sure that path cannot leak into public static generation. This is partly security and partly editorial trust: editors need reliable preview, but users should not see draft content by accident.
Plan the Rebuild or ISR Path
getStaticProps does not make CMS updates appear instantly by itself.
If the site is generated at build time, a content publish needs a rebuild or another freshness strategy. The article on static generation with CMS content and build‑time data covers that workflow in more detail.
Decide:
- which CMS events trigger a rebuild
- whether unpublishing triggers a rebuild
- whether ISR is used for selected routes
- how failed rebuilds are reported
- how scheduled content is handled
- whether editors understand the delay
This is where static content can become an operational problem. If every small content edit depends on a slow or fragile build, the page may be fast for users but frustrating for editors.
For production issues around freshness, headless CMS cache and revalidation debugging is the service angle. If the problem is build duration or memory pressure, Next.js and Vercel build timeout debugging is closer to the failure mode.
Return a Clean Page Model
The React component should not need to understand the CMS API.
Use getStaticProps to turn CMS data into a clean page model:
- required strings are present
- optional fields are explicit
- dates are serialisable
- images have the fields the component expects
- related entries are filtered
- rich text has enough metadata to render safely
- missing references are handled before rendering
This makes components easier to test and makes later CMS changes less risky. It also avoids the common pattern where every component reaches deeper into a CMS response until the template becomes tightly coupled to one API shape.
Use the Right Constraint, Not the Fastest Label
Static generation is strong when the content is stable, the route set is known and the publishing workflow can tolerate rebuild or ISR behaviour.
It is weaker when content freshness is immediate, the route set changes constantly or the CMS integration is already making builds unreliable. In those cases, the right answer may be ISR, server‑side rendering, an API‑backed client component or a smaller split between static and dynamic data.
The headless CMS SEO controls matrix is useful when deciding which fields and publishing controls need to survive that choice. Headless CMS integration is the broader implementation work around preview, metadata, rich text, publishing and editor trust.
getStaticProps is a useful tool. It is not a blanket answer for CMS content. Use it when the page can be generated ahead of time and the publishing workflow has been designed around that fact.