SKILL.md
Contentstack 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](../../lib/contentstack.ts) | getStack(), initLivePreview(), getPage() — core SDK and preview behavior |
| [app/page.tsx](../../app/page.tsx) | Server page: reads Live Preview searchParams, applies livePreviewQuery, fetches page |
| [components/ContentstackLivePreview.tsx](../../components/ContentstackLivePreview.tsx) | Client component: calls initLivePreview() when preview is enabled |
| [lib/types.ts](../../lib/types.ts) | TypeScript shapes for Page and nested modular blocks (matches seeded content) |
| [app/layout.tsx](../../app/layout.tsx) | Imports [app/globals.css](../../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](../../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.
livepreview,contenttypeuid,entryuid,preview_timestamp). [app/page.tsx](../../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](../../components/ContentstackLivePreview.tsx) runs
initLivePreview()insideuseEffectwhenNEXTPUBLICCONTENTSTACK_PREVIEW === "true". That usesssr: trueandmode: "builder"in [lib/contentstack.ts](../../lib/contentstack.ts).
Content query
- Default page fetch uses content type
page, fieldurlwithQueryOperation.EQUALS, wired in [lib/contentstack.ts](../../lib/contentstack.ts). - When preview is enabled,
contentstack.Utils.addEditableTagsis applied to the entry for visual building.
Environment variables
Documented in [README.md](../../README.md). All are NEXTPUBLIC* in this template (browser-visible). Typical set:
NEXTPUBLICCONTENTSTACKAPIKEYNEXTPUBLICCONTENTSTACKDELIVERYTOKENNEXTPUBLICCONTENTSTACKPREVIEWTOKENNEXTPUBLICCONTENTSTACK_REGIONNEXTPUBLICCONTENTSTACK_ENVIRONMENTNEXTPUBLICCONTENTSTACK_PREVIEW
Optional overrides for hosts (used internally at Contentstack) appear in [lib/contentstack.ts](../../lib/contentstack.ts): NEXTPUBLICCONTENTSTACKCONTENTDELIVERY, NEXTPUBLICCONTENTSTACKPREVIEWHOST, NEXTPUBLICCONTENTSTACKCONTENTAPPLICATION, NEXTPUBLICCONTENTSTACKIMAGEHOSTNAME (see [next.config.mjs](../../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