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
publishedAtvalue. - 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=developmentenables preview behavior by default.LEADCMS_PREVIEW=trueforces preview behavior.LEADCMS_PREVIEW=falseforces published-only behavior.
Best practices to avoid duplicates
- Pass
userUidin preview routes so user-specific draft variants can be resolved consistently. - Use base slugs for normal navigation and reserve UID-suffixed slugs for preview-only links.
- Sort by
publishedAtconsistently and decide how to place unpublished drafts in lists. - Keep list generation and detail resolution aligned by using the same
localeanduserUidcontext.
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: