Guides setup, development, and troubleshooting of the Next.js and Enonic XP headless integration (Next.XP framework). Covers Enonic adapter configuration, content type to React component mapping, Guillotine GraphQL data fetching, Content Studio preview mode, and draft/master branch switching. Use when building a Next.js frontend powered by Enonic XP, configuring the Next.XP adapter, mapping content types to components, fetching Enonic content via Guillotine in Next.js, or debugging Content Studio preview. Don't use for traditional server-side Enonic XP rendering, standalone Guillotine queries without Next.js, non-Next.js frontend frameworks with Enonic, or React4XP embedded rendering.
Step 1: Identify the workspace integration surface
next.config.*, package.json with next dependency), Enonic XP app markers (build.gradle with com.enonic.xp), or existing Next.XP adapter references (@enonic/nextjs-adapter).node scripts/find-nextxp-targets.mjs . to inventory Next.js projects, .env files with ENONIC_* variables, component mapping files (_mappings.ts), and Guillotine query files when a Node runtime is available.package.json, .env, and src/components/_mappings.ts manually to identify the integration surface.Step 2: Configure the Enonic adapter
references/nextxp-reference.md before writing or modifying configuration..env (or .env.local for local development) file in the Next.js project root with the required variables:
ENONIC_API_TOKEN — shared secret for preview mode authentication.ENONIC_APP_NAME — fully qualified Enonic application name (e.g., com.example.myproject).ENONIC_MAPPINGS — locale-to-project/site mapping (e.g., en:intro/hmdb).ENONIC_API — base URL for the Guillotine API endpoint (e.g., http://127.0.0.1:8080/site).@enonic/nextjs-adapter package if not already present: npm install @enonic/nextjs-adapter.@enonic/nextjs-adapter/baseMappings at the top of src/components/_mappings.ts to register built-in component renderers.nextxp-template or contains the expected file structure: src/components/_mappings.ts, src/app/[locale]/[[...contentPath]]/page.tsx, and API routes under src/app/api/.references/compatibility.md to confirm version requirements between @enonic/nextjs-adapter (v4.x), Next.js (16+), React (19), and Enonic XP.Step 3: Map content types to React components
references/nextxp-reference.md for the component registry API and mapping patterns.references/examples.md for complete content type mapping examples including queries, views, and processors.src/components/queries/ that fetches the fields specific to that content type using type introspection (... on AppName_ContentTypeName).
b. For content types with HTML area (rich text) fields, use richTextQuery(fieldName) from @enonic/nextjs-adapter to generate the query fragment. See references/nextxp-reference.md for the rich text rendering section.
c. Create a React view component in src/components/views/ that accepts FetchContentResult props and renders the fetched data. Use RichTextView from @enonic/nextjs-adapter/views/RichTextView for HTML area fields.
d. Register both in src/components/_mappings.ts using ComponentRegistry.addContentType().src/main/resources/site/pages/, parts/, or layouts/.
b. Create a corresponding React component in src/components/pages/, parts/, or layouts/. Use LayoutProps for layouts and the named RegionView export for individual region rendering.
c. Register using ComponentRegistry.addPage(), ComponentRegistry.addPart(), or ComponentRegistry.addLayout().LayoutProps type and RegionView (singular, named export) for individual regions instead of RegionsView.APP_NAME and APP_NAME_UNDERSCORED imports from @enonic/nextjs-adapter to keep content type references dynamic.Step 4: Configure Guillotine data fetching
references/nextxp-reference.md for the Guillotine query structure and variable passing.$path:ID! as the primary variable for content retrieval via guillotine { get(key:$path) { ... } }.... on AppName_ContentTypeName { data { ... } }.richTextQuery(fieldName) from the adapter instead of querying the field directly. Render with RichTextView from @enonic/nextjs-adapter/views/RichTextView.query(path, context, config) and variables(path, context, config) functions.ComponentRegistry.setCommonQuery() for data shared across all page components. Remove the common query if not needed to optimize performance.getUrl() and getAsset() helper functions from the adapter for URL handling that works in both standalone and Content Studio preview modes.ComponentRegistry.addMacro() before other components that use RichTextView. See references/nextxp-reference.md for the macro registration API.Step 5: Enable Content Studio preview mode
references/nextxp-reference.md for full preview architecture details.Next.XP app in Enonic XP: XP Menu → Applications → Install → search "Next.XP".http://127.0.0.1:3000 and secret matching ENONIC_API_TOKEN.nextjs.default.url = <Next.js app URL>
nextjs.default.secret = <shared secret>
draft branch, while the public Next.js frontend uses the master (published) branch.getUrl() in all component links to ensure URLs resolve correctly across preview, inline, and edit modes in Content Studio.references/troubleshooting.md for diagnostic steps.Step 6: Deploy to production
references/nextxp-reference.md for the deployment checklist.enonic cloud app install./site, public path /api).ENONIC_API, ENONIC_APP_NAME, ENONIC_API_TOKEN, ENONIC_MAPPINGS.Step 7: Validate the integration
node scripts/find-nextxp-targets.mjs . to confirm the adapter, mappings, and env configuration still resolve correctly.http://localhost:3000 with published content.validateData() from @enonic/nextjs-adapter in the page handler to catch invalid content responses. See references/nextxp-reference.md for the SSG page handler pattern.npm run build) to catch TypeScript or build errors.references/troubleshooting.md for preview proxy diagnostics, token mismatch detection, and CORS issues.http://localhost:8080/site/<project>.@enonic/nextjs-adapter imports fail, check references/compatibility.md for version requirements and confirm the package is installed.draft to master branch)._mappings.ts use the correct fully-qualified content type or component name with APP_NAME.