contentstack-kickstart
por contentstack
Use when changing Contentstack SDK usage, Live Preview, env configuration, or content queries in kickstart-next-ssr.
npx skills add https://github.com/contentstack/kickstart-next-ssr --skill contentstack-kickstartContentstack kickstart – kickstart-next-ssr
When to use
- Editing how the stack is created or how Live Preview is wired
- Adding or changing content types, queries, or types for entries
- Updating environment variable names or documentation
Instructions
Entry points in this repo
| File | Role |
|---|---|
| lib/contentstack.ts | getStack(), initLivePreview(), getPage() — core SDK and preview behavior |
| app/page.tsx | Server page: reads Live Preview searchParams, applies livePreviewQuery, fetches page |
| components/ContentstackLivePreview.tsx | Client component: calls initLivePreview() when preview is enabled |
| lib/types.ts | TypeScript shapes for Page and nested modular blocks (matches seeded content) |
| app/layout.tsx | Imports app/globals.css and mounts <ContentstackLivePreview /> after {children} |
Request isolation (getStack)
- Always create a fresh stack per server request when handling delivery or preview on the server. See the comments in lib/contentstack.ts: a shared instance can leak Live Preview configuration across concurrent requests.
getPage(url, stackInstance?)accepts an optional stack so the caller can configure Live Preview on the same instance before fetching.
Live Preview (SSR)
- URL/query: Contentstack adds query parameters (e.g.
live_preview,content_type_uid,entry_uid,preview_timestamp). app/page.tsx reads them fromsearchParams. - Server: If
live_previewis present, callstack.livePreviewQuery({ ... })on the stack fromgetStack(), then pass that stack intogetPage("/", stack). - Client: components/ContentstackLivePreview.tsx runs
initLivePreview()insideuseEffectwhenNEXT_PUBLIC_CONTENTSTACK_PREVIEW === "true". That usesssr: trueandmode: "builder"in lib/contentstack.ts.
Content query
- Default page fetch uses content type
page, fieldurlwithQueryOperation.EQUALS, wired in lib/contentstack.ts. - When preview is enabled,
contentstack.Utils.addEditableTagsis applied to the entry for visual building.
Environment variables
Documented in README.md. All are NEXT_PUBLIC_* in this template (browser-visible). Typical set:
NEXT_PUBLIC_CONTENTSTACK_API_KEYNEXT_PUBLIC_CONTENTSTACK_DELIVERY_TOKENNEXT_PUBLIC_CONTENTSTACK_PREVIEW_TOKENNEXT_PUBLIC_CONTENTSTACK_REGIONNEXT_PUBLIC_CONTENTSTACK_ENVIRONMENTNEXT_PUBLIC_CONTENTSTACK_PREVIEW
Optional overrides for hosts (used internally at Contentstack) appear in lib/contentstack.ts: NEXT_PUBLIC_CONTENTSTACK_CONTENT_DELIVERY, NEXT_PUBLIC_CONTENTSTACK_PREVIEW_HOST, NEXT_PUBLIC_CONTENTSTACK_CONTENT_APPLICATION, NEXT_PUBLIC_CONTENTSTACK_IMAGE_HOSTNAME (see next.config.mjs for image host allowlist).
Dependencies
@contentstack/delivery-sdk— stack and queries@contentstack/live-preview-utils—ContentstackLivePreview.init, types likeIStackSdk@timbenniks/contentstack-endpoints— region and endpoint resolutionisomorphic-dompurify— sanitization where used in UI