Drafts & Previews

When building with LeadCMS, you’ll often work with content that is not yet published or belongs to a single user’s preview session. These scenarios are handled by:

  • Drafts – content without a valid past publishedAt value.
  • Temporary previews – user-specific draft files, typically using a slug suffix like about-us-<userUid>.

In SDK v3+, preview behavior is environment-based. You no longer pass includeDrafts booleans through query APIs.

Understanding drafts vs previews

Drafts

Content is considered published only when publishedAt exists and is in the past. Missing/future publishedAt means draft. In production workflows, draft content is excluded by default.

Temporary user previews

During live editing, preview flows can create user-specific local files where the slug includes a GUID-like user UID. The SDK can resolve these variants and fall back to base content when needed.

Loading draft and preview content

Use current SDK signatures:

// Single page
const page = getCMSContentBySlugForLocale(slug, locale, userUid)

// Lists
const slugs = getAllContentSlugsForLocale(locale, ["blog-post"], userUid)
const posts = slugs
  .map((s) => getCMSContentBySlugForLocale(s, locale, userUid))
  .filter((p): p is CMSContent => p !== null)

Draft visibility is controlled by preview mode:

  • NODE_ENV=development enables preview behavior by default.
  • LEADCMS_PREVIEW=true forces preview behavior.
  • LEADCMS_PREVIEW=false forces published-only behavior.

Best practices to avoid duplicates

  1. Pass userUid in preview routes so user-specific draft variants can be resolved consistently.
  2. Use base slugs for normal navigation and reserve UID-suffixed slugs for preview-only links.
  3. Sort by publishedAt consistently and decide how to place unpublished drafts in lists.
  4. Keep list generation and detail resolution aligned by using the same locale and userUid context.

Summary

Draft and preview handling is built into the modern LeadCMS SDK workflow. With environment-driven preview mode and user-aware slug resolution, you can render drafts safely in preview contexts while keeping production output clean.

Next steps

With drafts and preview logic in place, you're ready to set up a preview server or move to deployment. Continue with: