Live Preview

When editors update content in LeadCMS, they often want to see changes reflected immediately on the site—even before publishing. LeadCMS supports live preview (also called temp user preview) through watcher-driven local files and SDK preview mode.

Current implementation

Live preview is delivered through a combination of the LeadCMS SSE watcher, user-specific draft files and environment-based SDK behavior:

  • The watch command listens for draft-updated and content-updated events from the CMS. When an editor starts editing a page, the CMS sends a draft-updated event that includes a user ID.
  • The watcher creates/updates files in .leadcms/content using {slug}-{userUid} naming (MDX or JSON) and marks draft state in local content metadata.
  • SDK APIs no longer use includeDrafts boolean parameters. Draft visibility is controlled by environment (NODE_ENV/LEADCMS_PREVIEW) plus optional userUid for user-specific draft resolution.

Typical usage:

  • Detail page queries: getCMSContentBySlugForLocale(slug, locale, userUid?)
  • List queries: getAllContentSlugsForLocale(locale, contentTypes, userUid?)

If the slug already includes a user GUID suffix (for example from a preview URL), the SDK detects it and resolves the matching user draft automatically, with fallback to base content when needed.

How preview mode is enabled

Preview mode is environment-driven in SDK v3+:

  • NODE_ENV=development enables preview behavior by default.
  • LEADCMS_PREVIEW=true explicitly enables preview mode.
  • LEADCMS_PREVIEW=false explicitly disables preview mode, even in development.

This applies to local SDK reads (getCMSContentBySlug*, getAllContentSlugs*, route helpers), not to CLI pull endpoints.

Running in preview mode

  • For local preview/dev servers, NODE_ENV=development is the standard setup.
  • If needed, force preview behavior with LEADCMS_PREVIEW=true.
  • To guarantee published-only reads in preview-like environments, set LEADCMS_PREVIEW=false.

Summary

Live preview uses watcher-generated user draft files plus SDK preview mode detection. In modern SDK versions, includeDrafts boolean parameters are removed; preview behavior is environment-based, and user-specific draft resolution is handled through userUid/preview slug patterns with safe fallbacks.

For details on draft handling and best practices, see the Draft Preview article. For instructions on configuring the watcher and preview server, see Preview Setup.