/sitecore-content-sdk-nextjs-app-router:content-sdk-app-router-editing-safe-renderingfrom Sitecore Content SDK - Next.js App Router
Ensures Content SDK App Router components render correctly in SitecoreAI Pages editing, preview, and design library. Handles draftMode, editing data, chromes, and selectable empty fields. Use when a component breaks or differs in the editor.
Ships in Sitecore Content SDK - Next.js App Router. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Ensure components behave correctly in SitecoreAI editing, preview, and design library. This app uses draftMode() for editing data: the plain template reads it from the request headers, the Cache Components template from searchParams.
<label> jumps focus into its input instead of selecting the field. See "Authoring-safe components" below.draftMode(); when enabled, get the preview data (plain template: client.getPreviewData(await headers()); Cache Components: await searchParams), use isDesignLibraryPreviewData(...) to choose getDesignLibraryData vs getPreview; otherwise use getPage. Editing routes: config route uses createEditingConfigRouteHandler, render route uses createEditingRenderRouteHandlers; set dynamic = 'force-dynamic' on both in the plain template; with cacheComponents the segment config is not needed.draftMode() in Server Components (e.g. in the page or [site] layout). When draft.isEnabled, the plain template calls client.getPreviewData(await headers()) and passes the result to isDesignLibraryPreviewData, client.getDesignLibraryData or client.getPreview; the Cache Components template passes await searchParams to the same calls instead (create-content-sdk-app templates, checked 2026-11-30). Use isDesignLibraryPreviewData(...) to distinguish: if true, use client.getDesignLibraryData(editingParams); otherwise use client.getPreview(editingParams). When not in draft mode, use getPage(path ?? [], { site, locale }).draftMode().src/app/api/editing/config/route.ts uses createEditingConfigRouteHandler({ components, clientComponents, metadata }) (import from .sitecore/component-map, .sitecore/component-map.client, .sitecore/metadata.json). src/app/api/editing/render/route.ts uses createEditingRenderRouteHandlers({}). Set export const dynamic = 'force-dynamic' on both. Do not duplicate client creation; config and render routes use the same component maps as the app.library-low-code on beta.atoms (low-code components, atoms:* bridge events) → content-sdk-app-router-atoms.sc_lang=de-DE and route=/ the body renders German but the dictionary and <html lang> stay English, because [locale] comes from the route, not sc_lang. Fix and details: content-sdk-app-router-dictionary-and-i18n § 8.<label htmlFor> in edit. These break authoring in Pages but pass unit tests — verify in a real editor.The plumbing above gets editing data into the page; this section keeps each component authorable once it's there. Symptom class: the page renders fine but an author can't select/manage a field in Pages. Applies to field-driven components (built with Text/RichText/Image/Link), especially anything interactive (forms, labelled inputs) or with optional fields.
Detect edit mode inside a component:
const { page } = useSitecore(); const isEditing = page.mode.isEditing; (useSitecore from @sitecore-content-sdk/nextjs; needs SitecoreProvider in the tree — the scaffold provides it). useSitecore() is the unified hook; there is no useSitecoreContext in Content SDK.const isEditing = !!fields?.SomeTextField?.metadata;. Sitecore emits field.metadata only in edit/preview. TextField/RichTextField extends FieldMetadata; ImageField/LinkField carry metadata only via & FieldMetadata, so read editing off a text field, not an image/link.1. Empty fields must stay authorable — gate on existence + edit mode, never on value. {fields?.Cta?.value?.href && <Link .../>} hides the field in the editor too, so there's nothing to click. The SDK helpers already render the default empty-field editing placeholder when field.metadata is present + value empty + editable !== false, and render null when empty + published — they just have to be rendered:
{fields?.Cta && (isEditing || fields.Cta.value?.href) && (
<Link field={fields.Cta} className="btn" />
)}
The existence check (fields?.Cta &&) stops an absent datasource field (e.g. a template you haven't finished building) from feeding undefined to the helper and crashing it. For repeated/flat fields (e.g. MetaValue1-3/MetaLabel1-3), render all rows in editing and .filter() to non-empty only when published.
2. Presentational forms must go inert in edit mode. A <form onSubmit={validate}> with a type="submit" button whose label is a field: clicking the button to author the label fires submit → validation errors + focus-stealing, so the field can't be managed.
function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
if (isEditing) return; // no validation in the editor
/* ...validate / set state... */
}
// submit button:
<button type={isEditing ? 'button' : 'submit'}>…</button> // also neutralizes Enter-to-submit
3. Field-backed <label htmlFor> steals the click. A <label htmlFor="x"><Text field={NameLabel}/></label> focuses its associated input on click (native label behavior) instead of selecting the label field. When the label is a sibling of its input (associated only via htmlFor), drop the association in edit:
<label htmlFor={isEditing ? undefined : 'x'} className="field-label">
<Text field={fields?.NameLabel} />
</label>
Published keeps the proper label → input a11y association (isEditing is false in normal mode).
4. Custom / transformed field presentation must stay editing-safe. If a component renders a field's raw field.value with its own markup — splitting a headline into animated spans, formatting a number, concatenating a string — instead of passing the field to <Text>/<RichText>, it never emits the editing chrome (field.metadata is dropped), so the field is not inline-editable in Pages (only the right-hand Content panel can change it), while sibling fields rendered through the SDK helpers stay inline-editable. This is the "some fields inline-edit, some don't" tell. Branch on edit mode — SDK field component when editing, the custom presentation when published:
export function KineticHeadline({ field }: { field: TextField }) {
const isEditing = !!field?.metadata; // server-safe edit signal
if (isEditing) return <Text field={field} tag="h1" />; // ONE editable node, un-split
return <h1 aria-label={String(field?.value ?? '')}>{/* split .kin-line spans */}</h1>;
}
Keep it one editable node in edit mode — never split one field across multiple <Text> (each would try to save the whole value → corruption). Preserve a11y in both branches (accessible name via aria-label; decorative pieces aria-hidden).
5. Integrated GraphQL (ComponentQuery) text fields must be fetched as { value jsonValue } — check the DATA path FIRST, not just the render. For a Shape-B / ComponentQuery component (fields.data.datasource…), a text field fetched as field(name:"X") { value } returns the raw string with no editing metadata, so it is not inline-editable no matter how you render it — <Text>, ed(), everything is downstream of a field that has no .metadata. This is the deeper cause behind "I already render through <Text> and it still won't edit": the render was never the blocker; the query was. Fix on the rendering item's ComponentQuery: request { value jsonValue } (the universal safe shape — .value keeps rendering working, .jsonValue carries { value, editable, metadata }), then render the metadata-bearing jsonValue:
type Cq<F> = F & { jsonValue?: F };
const ed = <F,>(f?: Cq<F>): F | undefined => f?.jsonValue ?? f; // defensive: falls back to value-only
// ComponentQuery: Title: field(name:"Title") { value jsonValue }
<Text field={ed(item.Title)} /> // reads the editable jsonValue; still renders if jsonValue absent
Image/Link fields already use { jsonValue } (already editable). When a Shape-B field won't edit, read the LIVE ComponentQuery first — a { value } text selection is the smoking gun; don't just inspect the component. (See content-sdk-app-router-graphql-data-fetching for the query; the value-vs-jsonValue asymmetry also affects rendering.)
Verify in a real editor, not jest. All five only surface in Pages (they are metadata-driven). A structural unit test that reads props directly passes regardless — Playwright/manual editor smoke is the gate.
'use cache' (Cache Components): editing must always see the current draft.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
sitecore, content-sdk, editing, preview, draft-mode, app-router
17 skills in this plugin
/content-sdk-app-router-atom-createWrites a Content SDK atom (beta.atoms): atom vs component, field schemas and enum tokens, renderer, catalog and registry keys, container slots, lock lifecycle, mock-MMS proof. Use when adding or changing an atom. Not wiring atoms into an app./content-sdk-app-router-atomsContent SDK Atoms (beta.atoms only): catalog, atomsConfig, ComponentRef rendering, lock CI gate, runtime CSS, Content Kit install, null-render traps. Use when wiring atoms or a low-code component renders nothing. Not code components or stable apps./content-sdk-app-router-cache-components-and-osrnpx claudepluginhub chris1415/sitecore-skills-pocs --plugin sitecore-content-sdk-nextjs-app-routerOther plugins' skills for the same job