create-content-sdk-app 2.2.0 → 2.2.1-beta.atoms.20260709124639

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/templates/nextjs/.agents/docs/AGENTS-key-concepts.md +33 -0
  2. package/dist/templates/nextjs/.agents/docs/AGENTS-overview.md +25 -0
  3. package/dist/templates/nextjs/.agents/docs/AGENTS-router-specifics.md +57 -0
  4. package/dist/templates/nextjs/.agents/docs/AGENTS-workflows-and-boundaries.md +20 -0
  5. package/dist/templates/nextjs/.agents/docs/README.md +12 -0
  6. package/dist/templates/nextjs/.agents/skills/content-sdk-component-data-strategy/SKILL.md +13 -25
  7. package/dist/templates/nextjs/.agents/skills/content-sdk-component-registration/SKILL.md +13 -24
  8. package/dist/templates/nextjs/.agents/skills/content-sdk-component-scaffold/SKILL.md +13 -22
  9. package/dist/templates/nextjs/.agents/skills/content-sdk-component-variants/SKILL.md +11 -24
  10. package/dist/templates/nextjs/.agents/skills/content-sdk-dictionary-and-i18n/SKILL.md +11 -23
  11. package/dist/templates/nextjs/.agents/skills/content-sdk-editing-safe-rendering/SKILL.md +12 -25
  12. package/dist/templates/nextjs/.agents/skills/content-sdk-field-usage-image-link-text/SKILL.md +12 -24
  13. package/dist/templates/nextjs/.agents/skills/content-sdk-graphql-data-fetching/SKILL.md +14 -26
  14. package/dist/templates/nextjs/.agents/skills/content-sdk-multisite-management/SKILL.md +13 -25
  15. package/dist/templates/nextjs/.agents/skills/content-sdk-route-configuration/SKILL.md +14 -26
  16. package/dist/templates/nextjs/.agents/skills/content-sdk-site-setup-and-env/SKILL.md +12 -24
  17. package/dist/templates/nextjs/.agents/skills/content-sdk-sitemap-robots/SKILL.md +11 -25
  18. package/dist/templates/nextjs/.agents/skills/content-sdk-troubleshoot-editing/SKILL.md +11 -27
  19. package/dist/templates/nextjs/.agents/skills/content-sdk-upgrade-assistant/SKILL.md +11 -24
  20. package/dist/templates/nextjs/.cursor/rules/general.mdc +9 -74
  21. package/dist/templates/nextjs/.cursor/rules/javascript.mdc +8 -101
  22. package/dist/templates/nextjs/.cursor/rules/project-setup.mdc +4 -91
  23. package/dist/templates/nextjs/.cursor/rules/sitecore.mdc +10 -139
  24. package/dist/templates/nextjs/.windsurfrules +6 -181
  25. package/dist/templates/nextjs/AGENTS.md +11 -116
  26. package/dist/templates/nextjs/CLAUDE.md +9 -5
  27. package/dist/templates/nextjs/Skills.md +24 -79
  28. package/dist/templates/nextjs/copilot-instructions.md +9 -168
  29. package/dist/templates/nextjs-app-router/.agents/docs/AGENTS-key-concepts.md +33 -0
  30. package/dist/templates/nextjs-app-router/.agents/docs/AGENTS-overview.md +34 -0
  31. package/dist/templates/nextjs-app-router/.agents/docs/AGENTS-router-specifics.md +70 -0
  32. package/dist/templates/nextjs-app-router/.agents/docs/AGENTS-workflows-and-boundaries.md +20 -0
  33. package/dist/templates/nextjs-app-router/.agents/docs/README.md +12 -0
  34. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-data-strategy/SKILL.md +13 -25
  35. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-registration/SKILL.md +14 -26
  36. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-scaffold/SKILL.md +14 -26
  37. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-component-variants/SKILL.md +11 -24
  38. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-dictionary-and-i18n/SKILL.md +12 -25
  39. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-editing-safe-rendering/SKILL.md +11 -25
  40. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-field-usage-image-link-text/SKILL.md +11 -24
  41. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-graphql-data-fetching/SKILL.md +15 -25
  42. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-multisite-management/SKILL.md +13 -25
  43. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-route-configuration/SKILL.md +14 -26
  44. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-site-setup-and-env/SKILL.md +11 -24
  45. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-sitemap-robots/SKILL.md +11 -25
  46. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-troubleshoot-editing/SKILL.md +12 -27
  47. package/dist/templates/nextjs-app-router/.agents/skills/content-sdk-upgrade-assistant/SKILL.md +11 -24
  48. package/dist/templates/nextjs-app-router/.cursor/rules/app-router-setup.mdc +4 -107
  49. package/dist/templates/nextjs-app-router/.cursor/rules/general.mdc +9 -73
  50. package/dist/templates/nextjs-app-router/.cursor/rules/javascript.mdc +7 -100
  51. package/dist/templates/nextjs-app-router/.cursor/rules/sitecore.mdc +7 -161
  52. package/dist/templates/nextjs-app-router/.windsurfrules +6 -286
  53. package/dist/templates/nextjs-app-router/AGENTS.md +14 -131
  54. package/dist/templates/nextjs-app-router/CLAUDE.md +9 -5
  55. package/dist/templates/nextjs-app-router/Skills.md +24 -79
  56. package/dist/templates/nextjs-app-router/copilot-instructions.md +9 -270
  57. package/dist/templates/nextjs-app-router-cache-components/.agents/docs/AGENTS-key-concepts.md +50 -0
  58. package/dist/templates/nextjs-app-router-cache-components/.agents/docs/AGENTS-overview.md +45 -0
  59. package/dist/templates/nextjs-app-router-cache-components/.agents/docs/AGENTS-router-specifics.md +85 -0
  60. package/dist/templates/nextjs-app-router-cache-components/.agents/docs/AGENTS-workflows-and-boundaries.md +21 -0
  61. package/dist/templates/nextjs-app-router-cache-components/.agents/docs/README.md +12 -0
  62. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-cache-components-and-osr/SKILL.md +16 -56
  63. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-component-data-strategy/SKILL.md +13 -27
  64. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-component-registration/SKILL.md +14 -26
  65. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-component-scaffold/SKILL.md +14 -27
  66. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-component-variants/SKILL.md +11 -24
  67. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-dictionary-and-i18n/SKILL.md +12 -28
  68. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-editing-safe-rendering/SKILL.md +11 -29
  69. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-field-usage-image-link-text/SKILL.md +11 -24
  70. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-graphql-data-fetching/SKILL.md +15 -55
  71. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-multisite-management/SKILL.md +13 -26
  72. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-route-configuration/SKILL.md +14 -34
  73. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-site-setup-and-env/SKILL.md +11 -27
  74. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-sitemap-robots/SKILL.md +11 -26
  75. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-troubleshoot-editing/SKILL.md +12 -30
  76. package/dist/templates/nextjs-app-router-cache-components/.agents/skills/content-sdk-upgrade-assistant/SKILL.md +11 -25
  77. package/dist/templates/nextjs-app-router-cache-components/.cursor/rules/app-router-setup.mdc +4 -121
  78. package/dist/templates/nextjs-app-router-cache-components/.cursor/rules/general.mdc +9 -73
  79. package/dist/templates/nextjs-app-router-cache-components/.cursor/rules/javascript.mdc +8 -104
  80. package/dist/templates/nextjs-app-router-cache-components/.cursor/rules/sitecore.mdc +8 -192
  81. package/dist/templates/nextjs-app-router-cache-components/.windsurfrules +6 -317
  82. package/dist/templates/nextjs-app-router-cache-components/AGENTS.md +6 -164
  83. package/dist/templates/nextjs-app-router-cache-components/CLAUDE.md +9 -5
  84. package/dist/templates/nextjs-app-router-cache-components/Skills.md +25 -83
  85. package/dist/templates/nextjs-app-router-cache-components/copilot-instructions.md +9 -312
  86. package/package.json +6 -6
@@ -0,0 +1,33 @@
1
+ # Key concepts (Pages Router)
2
+
3
+ Optional, on-demand detail. The compact guide is [AGENTS.md](../../AGENTS.md).
4
+
5
+ ## Middleware (Edge proxy)
6
+
7
+ - **Where:** `src/proxy.ts`. Next.js runs middleware from `middleware.ts` at root or in `src/` — if the app only has `proxy.ts`, add `src/middleware.ts` that re-exports it.
8
+ - **What it does:** Runs on each request (respecting the `config.matcher`). Chain order is **fixed:** PreviewProxy → BotTrackingProxy → MultisiteProxy → RedirectsProxy → PersonalizeProxy. PreviewProxy authorizes preview requests first; multisite resolves site (e.g. hostname or cookie) and rewrites; redirects and personalization run after.
9
+ - **Config:** Uses `sitecore.config.ts` (multisite, redirects, personalize) and `.sitecore/sites.json`. **Do not change proxy order.** Use the `skip` callback and matcher to exclude `/api`, `/_next`, static files, and health checks so the proxy stays lightweight.
10
+
11
+ ## SitecoreClient
12
+
13
+ - **Where:** Single shared instance in `src/lib/sitecore-client.ts` — `new SitecoreClient({ ...scConfig })` with config from `sitecore.config.ts`.
14
+ - **Use for:** `getPage`, `getDictionary`, `getComponentData`, `getPreview`, `getDesignLibraryData`, `getPagePaths`. All Sitecore data fetching in the app goes through this client (in `[[...path]].tsx` getStaticProps/getServerSideProps and in API routes).
15
+ - **Do not:** Create a second client or instantiate SitecoreClient elsewhere. Path comes from `extractPath(context)`; locale from `context.locale` (Next.js i18n).
16
+
17
+ ## Catch-all route
18
+
19
+ - **Where:** `src/pages/[[...path]].tsx`. This is the **only** page component that renders Sitecore content; the optional `[[...path]]` segment captures the content path.
20
+ - **Flow:** Use `extractPath(context)` (from `@sitecore-content-sdk/nextjs/utils`) to get the path array; use `context.locale` for locale. In getStaticProps/getServerSideProps: `client.getPage(path, { locale: context.locale })`, then `client.getDictionary({ site: page.siteName, locale: page.locale })` and `client.getComponentData(page.layout, context, components)`. For SSG, paths from `client.getPagePaths(sites, context?.locales)` with `sites` from `.sitecore/sites.json`. For preview, use `context.preview` and `context.previewData` with `client.getPreview(context.previewData)` or `client.getDesignLibraryData(context.previewData)`.
21
+ - **Do not:** Add another page or catch-all for Sitecore content; keep this single entry point.
22
+
23
+ ## How locale works
24
+
25
+ - **Config:** `next.config.js` → `i18n.locales` and `i18n.defaultLocale`. Match (or subset) Sitecore languages. There is no `[locale]` in the URL path; Next.js i18n handles locale via its built-in behavior (e.g. prefix or cookie).
26
+ - **In the app:** Per-request locale is `context.locale` in `getStaticProps` and `getServerSideProps`. Pass it to `client.getPage(path, { locale: context.locale })`. After fetching the page, use `page.siteName` and `page.locale` (or `context.locale`) for `client.getDictionary` and `client.getComponentData`.
27
+ - **Do not:** Assume locale from headers or a different source; always use `context.locale` and the page's site/locale for Sitecore calls.
28
+
29
+ ## Component map, editing, env
30
+
31
+ - **Component map:** `.sitecore/component-map.ts` — auto-generated from `src/components/` during `npm run dev` (watch) and `npm run build`. Do not edit manually unless needed. Used by `getComponentData` and by the editing API routes.
32
+ - **Editing/preview:** Use `context.preview` and `context.previewData` in the catch-all page; when in preview, use `client.getPreview(context.previewData)` or `client.getDesignLibraryData(context.previewData)`. Editing API routes: `src/pages/api/editing/config.ts`, `render.ts`, `feaas/render.ts`.
33
+ - **Env:** All config via environment variables in `sitecore.config.ts`. Document vars in `.env.example` (or `.env.remote.example` / `.env.container.example`); never commit `.env` or `.env.local`.
@@ -0,0 +1,25 @@
1
+ # Project overview (Pages Router)
2
+
3
+ This is a **Sitecore Content SDK** application built with **Next.js (Pages Router)** and **TypeScript**. AI agents work as developer assistants within this scaffolded head application. The app integrates with Sitecore XM Cloud for content, supports multisite and i18n, and uses Next.js API routes and Edge middleware for routing and SEO.
4
+
5
+ **Scope:** This file applies to **this application only** (a scaffolded head app). It is **not** the Content SDK monorepo — for SDK package development use that repo's `AGENTS.md`. Here we edit app code and config (pages, components, API routes, config); we do not modify SDK packages or CI.
6
+
7
+ ## Application structure
8
+
9
+ ```
10
+ src/
11
+ pages/ # Next.js Pages Router
12
+ [[...path]].tsx # Catch-all Sitecore page (SSG or SSR)
13
+ _app.tsx
14
+ 404.tsx, 500.tsx, _error.tsx
15
+ api/ # API routes (sitemap, robots, editing, healthz)
16
+ components/ # React components (Sitecore + app-specific)
17
+ lib/ # sitecore-client, component-props
18
+ Layout.tsx, Providers.tsx, Bootstrap.tsx, Scripts.tsx
19
+ proxy.ts # Edge middleware (multisite, redirects, personalize)
20
+ .sitecore/ # component-map.ts, import-map.ts, sites.json, metadata.json
21
+ sitecore.config.ts # Sitecore config (api, defaultSite, defaultLanguage, multisite, etc.)
22
+ next.config.js # i18n (locales, defaultLocale), rewrites, images
23
+ ```
24
+
25
+ **Component map:** `.sitecore/component-map.ts` is auto-generated from `src/components/` during `npm run dev` (watch) and `npm run build`. No manual action needed; the generator scans `src/components/` and creates entries for all Sitecore-registered components.
@@ -0,0 +1,57 @@
1
+ # Next.js Pages Router specifics
2
+
3
+ Optional, on-demand detail. The compact guide is [AGENTS.md](../../AGENTS.md).
4
+
5
+ ## Routing and data fetching
6
+
7
+ - **_app.tsx:** Wraps the app and receives the page/layout from the catch-all's getStaticProps/getServerSideProps. Do not fetch Sitecore data in _app; all data flows from `[[...path]].tsx`.
8
+ - **Single page for Sitecore content:** `src/pages/[[...path]].tsx` is the catch-all. Path comes from `extractPath(context)` (from `@sitecore-content-sdk/nextjs/utils`); locale from `context.locale` (Next.js i18n).
9
+ - **SSG:** Uses `getStaticPaths` and `getStaticProps`. Paths from `client.getPagePaths(sites, context?.locales)` with `sites` from `.sitecore/sites.json`. Use `revalidate` for ISR.
10
+ - **SSR:** Uses `getServerSideProps` only; no `getStaticPaths`.
11
+ - **Preview:** `context.preview` and `context.previewData`; use `client.getPreview(context.previewData)` or `client.getDesignLibraryData(context.previewData)` when applicable.
12
+ - **Page data:** `client.getPage(path, { locale: context.locale })`, then `client.getDictionary({ site: page.siteName, locale: page.locale })` and `client.getComponentData(page.layout, context, components)` for component props.
13
+
14
+ ## i18n (Pages Router)
15
+
16
+ - **Config:** `next.config.js` → `i18n.locales` and `i18n.defaultLocale`. Match (or subset) Sitecore languages.
17
+ - **Per-request locale:** Provided by Next.js as `context.locale` in `getStaticProps` / `getServerSideProps`. No `[locale]` in the path; locale is from Next.js i18n.
18
+
19
+ ## Multisite and Edge middleware (proxy)
20
+
21
+ - **Site list:** `.sitecore/sites.json` — typically generated by the Sitecore CLI or deployment. Used by middleware and API routes. Avoid hand-editing unless you know the format.
22
+ - **Edge middleware:** Implemented in **`src/proxy.ts`**. Next.js only runs middleware from a file named `middleware.ts` at root or in `src/`. If this app has only `proxy.ts`, add `src/middleware.ts` that re-exports it (e.g. `export { default } from './proxy';`) so the proxy runs.
23
+ - **Proxy chain (order matters):** `defineProxy(preview, botTracking, multisite, redirects, personalize).exec(req)`:
24
+ - **PreviewProxy** — authorizes preview requests on the internal editing host; no-op elsewhere.
25
+ - **BotTrackingProxy** — bot detection.
26
+ - **MultisiteProxy** — resolves site from request (e.g. hostname or cookie), rewrites to internal path; uses `scConfig.api.edge` and `scConfig.multisite` (e.g. `useCookieResolution`).
27
+ - **RedirectsProxy** — handles redirects; uses `scConfig.redirects`, `scConfig.api.edge`, `scConfig.api.local`.
28
+ - **PersonalizeProxy** — personalization; uses `scConfig.personalize`; often disabled in dev.
29
+ - **Skip function:** Each proxy has a `skip` callback. Use it to avoid running on certain paths (e.g. `/api`, `/_next`, static files) for performance.
30
+ - **Config:** `sitecore.config.ts` → `multisite.enabled`, `redirects.enabled`, `personalize`; never commit secrets.
31
+
32
+ ## API routes
33
+
34
+ - **Sitemap:** `src/pages/api/sitemap.ts` — `SitemapMiddleware(scClient, sites).getHandler()`. Serves sitemap XML; uses `sites` from `.sitecore/sites.json`.
35
+ - **Robots:** `src/pages/api/robots.ts` — `RobotsMiddleware(scClient, sites).getHandler()`. Serves `robots.txt`; site can be resolved from request.
36
+ - **Editing:** `src/pages/api/editing/config.ts`, `render.ts`, `feaas/render.ts` — used by Sitecore Editor (XM Cloud); use SDK middleware/handlers and `.sitecore/component-map`, `.sitecore/metadata.json`.
37
+ - **Health:** `src/pages/api/healthz.ts` — health check. Rewrite in `next.config.js`: `/healthz` → `/api/healthz`.
38
+ - **Rewrites:** `next.config.js` → `rewrites()` for `/robots.txt`, `/sitemap*.xml`, `/feaas-render` to the corresponding API routes.
39
+
40
+ ## Sitecore client and config
41
+
42
+ - **Client:** `src/lib/sitecore-client.ts` — `new SitecoreClient({ ...scConfig })`. Use this instance for `getPage`, `getDictionary`, `getComponentData`, `getPreview`, `getPagePaths`, etc.
43
+ - **Config:** `sitecore.config.ts` — `defineConfig({ api, defaultSite, defaultLanguage, editingSecret, redirects, multisite, personalize })`. Use env vars; no hardcoded secrets.
44
+
45
+ ## Component map and layout
46
+
47
+ - **Component map:** `.sitecore/component-map.ts` — auto-generated from `src/components/` during `npm run dev` (watch) and `npm run build`. Do not edit manually unless needed.
48
+ - **Layout:** `Layout.tsx` renders page layout and placeholders; `Providers` wrap component props and page context; `Bootstrap` handles site name and preview mode.
49
+ - **404 / 500 / _error:** When the catch-all returns `notFound: true` (no page), Next.js renders `404.tsx`. When the server returns 500, Next.js renders `500.tsx`. Both can optionally fetch and show Sitecore error content via `client.getErrorPage(ErrorPage.NotFound)` / `ErrorPage.InternalServerError` in their getStaticProps (when `scConfig.generateStaticPaths`); otherwise they show a simple fallback. `_error.tsx` is Next.js's error boundary for uncaught errors (client and server); it does not fetch from Sitecore.
50
+
51
+ ## Best practices
52
+
53
+ - **Quick checks:** If path or locale is wrong, ensure you use `extractPath(context)` and `context.locale` (from getStaticProps/getServerSideProps); do not assume path or locale from elsewhere. Keep the proxy chain order (PreviewProxy → BotTrackingProxy → Multisite → Redirects → Personalize).
54
+ - **Security:** Use only environment variables in `sitecore.config.ts`; never hardcode API keys, editing secret, or host URLs. Do not expose secrets in client-side code or in logs. Validate and sanitize user input at boundaries.
55
+ - **Performance:** Keep middleware lightweight; use the proxy `skip` callback and `matcher` so middleware does not run on `/api`, `_next`, static files, or health checks. Use `revalidate` in getStaticProps for ISR where appropriate. Prefer server-side data fetching for Sitecore content.
56
+ - **Sitecore patterns:** Use SDK field components (`<Text>`, `<RichText>`, `<Image>`) and validate field existence before render. Regenerate `.sitecore/component-map.ts` with `npm run sitecore-tools:generate-map` or `npm run sitecore-tools:generate-map:watch`; edit the map manually only when the generator cannot handle the change. Keep the single Sitecore client instance in `lib/sitecore-client.ts` and pass it (or use it) in API routes and getStaticProps/getServerSideProps.
57
+ - **Consistency:** Follow the existing patterns in `[[...path]].tsx`, `_app.tsx`, and API routes. When adding API routes, add the corresponding rewrite in `next.config.js` and keep the middleware matcher in sync.
@@ -0,0 +1,20 @@
1
+ # Workflows and boundaries (Pages Router)
2
+
3
+ Optional, on-demand detail. Guardrails stay in [AGENTS.md](../../AGENTS.md).
4
+
5
+ ## Example agent tasks
6
+
7
+ - **Add a new Sitecore component:** Create the component under `src/components/` (map regenerates automatically during `npm run dev`; otherwise run `npm run sitecore-tools:generate-map`), and ensure it is rendered in the layout/placeholder as in existing components.
8
+ - **Add an API route:** Create the route under `src/pages/api/`, add a rewrite in `next.config.js` if the route should be reached from a public URL (e.g. `/my-path` → `/api/my-handler`), and ensure the proxy `matcher` in `proxy.ts` still excludes it (or add the path to the matcher exclusions if needed).
9
+
10
+ ## Boundaries
11
+
12
+ **Never edit:** `.next/`, `node_modules/`.
13
+
14
+ **Environment variables:** You may add new env vars when needed. Do it carefully: add the variable to `.env.example` (or `.env.remote.example` / `.env.container.example` in this template) with a placeholder or comment; never put real secrets in example files. If editing `.env.local` for local dev, add only the variable name and tell the user to set the value. **Never commit** `.env` or `.env.local` — they are gitignored.
15
+
16
+ **Edit with care:** `next.config.js` (rewrites, i18n), `sitecore.config.ts` (env only), `proxy.ts` (matcher and proxy order). When adding API routes or rewrites, keep middleware `matcher` and rewrite rules consistent.
17
+
18
+ **Focus on:** `src/pages/`, `src/components/`, `src/lib/`, `Layout.tsx`, `Providers.tsx`, `sitecore.config.ts`, `next.config.js`, `proxy.ts`. `.sitecore/component-map.ts` is auto-generated — do not edit manually.
19
+
20
+ **For head applications / empty starters:** Keep this app's `AGENTS.md` as the guide. Do not replace it with the Content SDK monorepo root `AGENTS.md` — that file describes the SDK source tree, not the head application.
@@ -0,0 +1,12 @@
1
+ # Layered AI docs (Pages Router)
2
+
3
+ Use [AGENTS.md](../../AGENTS.md) first (compact). Open **one** file below when you need depth.
4
+
5
+ | File | Use when |
6
+ |------|----------|
7
+ | [AGENTS-overview.md](AGENTS-overview.md) | Project scope and what this head app is |
8
+ | [AGENTS-key-concepts.md](AGENTS-key-concepts.md) | Middleware, SitecoreClient, catch-all, locale, component map |
9
+ | [AGENTS-router-specifics.md](AGENTS-router-specifics.md) | Routing, i18n, proxy, data fetching, API routes, layout |
10
+ | [AGENTS-workflows-and-boundaries.md](AGENTS-workflows-and-boundaries.md) | Example tasks and edit boundaries |
11
+
12
+ Skills: [.agents/skills/](../skills/) — load **one** [SKILL.md](https://agentskills.io) per task. See [Skills.md](../../Skills.md).
@@ -1,37 +1,25 @@
1
1
  ---
2
2
  name: content-sdk-component-data-strategy
3
- description: Component data for Pages Router: after getPage use client.getComponentData(page.layout, context, components) to resolve component props; pass result to layout renderer. All Sitecore-driven component data goes through this flow. Use when wiring component data or BYOC.
3
+ description: Layout data from getPage/getComponentData; path/locale from extractPath/context.
4
4
  ---
5
5
 
6
- # Content SDK Component Data Strategy (Pages Router)
6
+ # Component data strategy (Pages Router)
7
7
 
8
- This app **uses getComponentData**. After getPage, use **client.getComponentData(page.layout, context, components)** to resolve component props and pass the result to the layout renderer. All Sitecore-driven component data goes through this flow.
8
+ **Detail:** [AGENTS-router-specifics.md#routing-and-data-fetching](../../docs/AGENTS-router-specifics.md#routing-and-data-fetching)
9
9
 
10
- ## When to Use
10
+ ## When
11
11
 
12
- - User asks how to pass data to components, wire component props, or integrate custom/BYOC components.
13
- - Task involves getComponentData, component props, or BYOC.
14
- - User mentions "component data," "props," "BYOC," or "getComponentData."
12
+ - How component receives Sitecore data
13
+ - BYOC or serializable props to client
15
14
 
16
- ## How to perform
15
+ ## Rules
17
16
 
18
- - In [[...path]].tsx: getPage(path, { locale: context.locale }), then getDictionary, then getComponentData(page.layout, context, components). Return props to Layout; do not fetch in _app or in child components. Register BYOC in .sitecore/component-map.ts; getComponentData passes resolved props.
17
+ - Data from `getPage` + `getComponentData` in catch-all page
18
+ - Pass serializable props to client components
19
+ - BYOC must be registered in component map
19
20
 
20
- ## Hard Rules
21
+ ## Stop
21
22
 
22
- - **Flow in catch-all page:** In getStaticProps/getServerSideProps: (1) `client.getPage(path, { locale: context.locale })`, (2) `client.getDictionary({ site: page.siteName, locale: page.locale })`, (3) `client.getComponentData(page.layout, context, components)` to resolve component props. Return `{ props: { page, dictionary, componentProps }, notFound: !page }`. Pass these props to Providers and Layout; do not fetch Sitecore data in _app.
23
- - Do not fetch per-component data in parallel outside this flow unless the app pattern explicitly does so. All Sitecore-driven component data goes through getComponentData.
24
- - Single client instance; do not create a new client inside components. The client is used in getStaticProps/getServerSideProps and in API routes.
25
- - **BYOC or custom components:** Must be registered in `.sitecore/component-map.ts` and receive props in the shape the layout expects (e.g. fields, params). getComponentData will pass the resolved props.
26
- - Do not fetch layout or page data inside a child component (e.g. another getPage call); fetch at the catch-all page level and pass props via getComponentData and layout.
23
+ - Stop if introducing a second data-fetch path without clear need
27
24
 
28
- ## Stop Conditions
29
-
30
- - Stop if the user wants to fetch page/layout data inside a child component; recommend fetching in [[...path]].tsx and passing via getComponentData and layout.
31
- - Do not duplicate getComponentData or getPage logic across components; keep data fetching in the catch-all page only.
32
- - Do not fetch Sitecore data in _app; all data flows from [[...path]].tsx.
33
-
34
- ## References
35
-
36
- - content-sdk-graphql-data-fetching and [AGENTS.md](../../../AGENTS.md) for getPage, getComponentData, and data flow.
37
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
25
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,36 +1,25 @@
1
1
  ---
2
2
  name: content-sdk-component-registration
3
- description: Registers Sitecore components in .sitecore/component-map.ts so layout and editing can resolve them. Pages Router uses a single map; used by getComponentData and editing API routes. Use when registering a new component or when layout/editor cannot find a component.
3
+ description: Registers components in .sitecore/component-map.ts for Pages Router layout and editing.
4
4
  ---
5
5
 
6
- # Content SDK Component Registration (Pages Router)
6
+ # Component registration (Pages Router)
7
7
 
8
- Register components in the Sitecore component map so the layout and editing pipeline can resolve and render them. This app has a **single** map: `.sitecore/component-map.ts`.
8
+ **Detail:** [AGENTS-router-specifics.md#component-map-and-layout](../../docs/AGENTS-router-specifics.md#component-map-and-layout)
9
+ **Read first:** `.sitecore/component-map.ts`
9
10
 
10
- ## When to Use
11
+ ## When
11
12
 
12
- - After scaffolding or adding a new Sitecore component (must be registered).
13
- - User reports a component not rendering, "component not found," or layout/placeholder showing raw component name.
14
- - Task involves `.sitecore/component-map.ts`.
15
- - User asks how to register a component or fix component resolution.
13
+ - Component not found in layout/editor
14
+ - Task touches the component map
16
15
 
17
- ## How to perform
16
+ ## Rules
18
17
 
19
- - Open `.sitecore/component-map.ts` and add an entry mapping the layout component name to the React component import. The map is used by getComponentData and editing API routes; keep keys consistent with layout and existing entries.
18
+ - Every layout component must be in `.sitecore/component-map.ts`
19
+ - Prefer auto-generation from `src/components/`; edit manually only when generator cannot handle the case
20
20
 
21
- ## Hard Rules
21
+ ## Stop
22
22
 
23
- - Every component rendered from Sitecore layout must be registered in `.sitecore/component-map.ts`. Keep the map in sync with `src/components/`.
24
- - The map is used by `getComponentData(page.layout, context, components)` in the catch-all page and by editing API routes (`src/pages/api/editing/config.ts`, `render.ts`, `feaas/render.ts`).
25
- - Use consistent component names (same key in map as used in layout). Follow existing naming in the map.
26
- - Do not remove or rename registrations without updating all references (layout, getComponentData, editing routes).
23
+ - Stop if renaming map entries would break published layout without Sitecore-side update
27
24
 
28
- ## Stop Conditions
29
-
30
- - Stop if modifying the component map would break existing layout or editing; suggest a safe change or ask for confirmation.
31
- - Do not edit `.sitecore/metadata.json` or import-map unless the task explicitly requires it.
32
-
33
- ## References
34
-
35
- - [AGENTS.md](../../../AGENTS.md) for component map and editing routes.
36
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
25
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,34 +1,25 @@
1
1
  ---
2
2
  name: content-sdk-component-scaffold
3
- description: Creates new Sitecore components with correct file structure, props interface, and placement under src/components/. Use when adding a new component from scratch or scaffolding a component. Pages Router: register in .sitecore/component-map.ts only.
3
+ description: Creates new Sitecore components under src/components/. Pages Router; map auto-regenerates on dev/build.
4
4
  ---
5
5
 
6
- # Content SDK Component Scaffold (Pages Router)
6
+ # Component scaffold (Pages Router)
7
7
 
8
- Scaffold new Sitecore components so they integrate with the layout and editing pipeline. This app uses Pages Router with a single component map.
8
+ **Detail:** [AGENTS-router-specifics.md#component-map-and-layout](../../docs/AGENTS-router-specifics.md#component-map-and-layout)
9
+ **Read first:** `src/components/`
9
10
 
10
- ## When to Use
11
+ ## When
11
12
 
12
- - User asks to add a new Sitecore component, create a component from scratch, or scaffold a component.
13
- - Task involves creating a new React component that will be rendered from Sitecore layout/placeholders.
14
- - User mentions "new component," "add component," or "component file structure."
13
+ - Adding a new Sitecore component from scratch
14
+ - User asks for component file structure or props
15
15
 
16
- ## How to perform
16
+ ## Rules
17
17
 
18
- - Create a new file under `src/components/` (or existing feature folder). Define props (fields, params), export a single default component. Register in `.sitecore/component-map.ts` (content-sdk-component-registration). Run `npm run build` to verify.
18
+ - Place components under `src/components/`
19
+ - Map regenerates during `npm run dev` / `npm run build`; run `npm run sitecore-tools:generate-map` if dev is not running
19
20
 
20
- ## Hard Rules
21
+ ## Stop
21
22
 
22
- - Place components under `src/components/`. Use existing folder conventions.
23
- - Define a props interface with the component's fields (e.g. `fields: { title: Field; ... }`) and any params. Use types from `@sitecore-content-sdk/react` or the app's types.
24
- - Export a single default component; one component per file unless the app pattern differs.
25
- - After creating the component file, register it in `.sitecore/component-map.ts` (see content-sdk-component-registration). Do not leave the component unregistered. Pages Router has a single map used by getComponentData and editing API routes.
23
+ - Stop if unclear whether component needs client-side interactivity
26
24
 
27
- ## Stop Conditions
28
-
29
- - Do not create components in `.next/`, `node_modules/`, or build output.
30
-
31
- ## References
32
-
33
- - [AGENTS.md](../../../AGENTS.md) for app structure and component map.
34
- - [Skills.md](../../../Skills.md) for capability map. [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
25
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,36 +1,23 @@
1
1
  ---
2
2
  name: content-sdk-component-variants
3
- description: Implements component variants: different renderings or data-driven variants of the same component type. Pages Router: register in .sitecore/component-map.ts; getComponentData resolves props. Use when one component has multiple presentations.
3
+ description: Multiple renderings of one component type; regenerate component map after changes.
4
4
  ---
5
5
 
6
- # Content SDK Component Variants (Pages Router)
6
+ # Component variants (Pages Router)
7
7
 
8
- One component definition can have multiple presentations or data-driven variants. Component props are resolved by **getComponentData(page.layout, context, components)**; keep registration and layout aligned.
8
+ **Detail:** [AGENTS-router-specifics.md#component-map-and-layout](../../docs/AGENTS-router-specifics.md#component-map-and-layout)
9
9
 
10
- ## When to Use
10
+ ## When
11
11
 
12
- - User asks for different "variants," "versions," or "presentations" of a component.
13
- - Task involves rendering the same component type with different layouts or props based on data (e.g. variant field or style).
14
- - User mentions "component variants," "variations," or "multiple renderings."
12
+ - One component type with multiple presentations or variants
15
13
 
16
- ## How to perform
14
+ ## Rules
17
15
 
18
- - Prefer one component that accepts variant/style via props and branches internally; or multiple map entries if the app uses one key per variant. Use layout/fields/params for variant; register in `.sitecore/component-map.ts`. getComponentData resolves props; align with existing app convention.
16
+ - Follow existing variant patterns in `src/components/`
17
+ - Regenerate component map after changes
19
18
 
20
- ## Hard Rules
19
+ ## Stop
21
20
 
22
- - Prefer a single component registration that accepts variant/style data (e.g. params or fields) and branches internally, over multiple map entries for the same logical component unless the app pattern uses separate registrations per variant.
23
- - Use props (fields, params) from layout to decide variant; do not rely on global state or URL for variant selection when data comes from Sitecore. getComponentData passes the layout-driven props to the component.
24
- - Register in `.sitecore/component-map.ts` only. If the app uses one key per variant, register each; if one key with variant param, single registration. Follow existing app convention.
25
- - Keep the component map in sync with src/components/.
21
+ - Stop if variant rename would break layout without Sitecore update
26
22
 
27
- ## Stop Conditions
28
-
29
- - Stop if the variant model (one registration vs many) is unclear; ask or follow the app's existing pattern.
30
- - Do not add new component map entries without ensuring layout and editing can provide the corresponding data.
31
- - Do not assume variant field names (e.g. "variant," "style") without checking the layout definition.
32
-
33
- ## References
34
-
35
- - [AGENTS.md](../../../AGENTS.md) and content-sdk-component-registration for the map.
36
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
23
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,35 +1,23 @@
1
1
  ---
2
2
  name: content-sdk-dictionary-and-i18n
3
- description: Dictionary and i18n for Pages Router: Next.js i18n in next.config.js (i18n.locales, defaultLocale). Per-request locale is context.locale in getStaticProps/getServerSideProps. Fetch dictionary with client.getDictionary({ site: page.siteName, locale: page.locale }) after getPage. Use when adding or changing translated content or locale behavior.
3
+ description: Next.js i18n via next.config.js; locale from context.locale in data methods.
4
4
  ---
5
5
 
6
- # Content SDK Dictionary and i18n (Pages Router)
6
+ # Dictionary and i18n (Pages Router)
7
7
 
8
- This app uses **Next.js built-in i18n**. There is no [locale] in the URL path; locale is provided by Next.js as `context.locale` in getStaticProps/getServerSideProps.
8
+ **Detail:** [AGENTS-router-specifics.md#i18n-pages-router](../../docs/AGENTS-router-specifics.md#i18n-pages-router)
9
9
 
10
- ## When to Use
10
+ ## When
11
11
 
12
- - User asks to add or change translated content, locale, or dictionary.
13
- - Task involves getDictionary, Next.js i18n, or context.locale.
14
- - User mentions "dictionary," "i18n," "locale," or "translation."
12
+ - i18n locales, dictionary, or context.locale issues
15
13
 
16
- ## How to perform
14
+ ## Rules
17
15
 
18
- - Locales: `next.config.js` → i18n.locales, defaultLocale. In getStaticProps/getServerSideProps use context.locale; after getPage use client.getDictionary({ site: page.siteName, locale: page.locale }). Use a single getDictionary per request. Do not assume locale from headers.
16
+ - `next.config.js` → `i18n.locales` / `defaultLocale` aligned with Sitecore
17
+ - Always pass `context.locale` to `client.getPage`
19
18
 
20
- ## Hard Rules
19
+ ## Stop
21
20
 
22
- - **Config:** `next.config.js` `i18n.locales` and `i18n.defaultLocale`. Match (or subset) Sitecore languages.
23
- - **Per-request locale:** Use `context.locale` in getStaticProps and getServerSideProps. Pass it to `client.getPage(path, { locale: context.locale })`. After fetching the page, use `page.siteName` and `page.locale` (or `context.locale`) for `client.getDictionary({ site: page.siteName, locale: page.locale })` and for getComponentData.
24
- - Align locales in next.config.js with Sitecore languages (e.g. from sitecore.config.ts defaultLanguage). Use a single client.getDictionary per request for the active site/locale.
25
- - **Do not** assume locale from headers or a different source; always use `context.locale` and the page's site/locale for Sitecore calls.
21
+ - Stop if assuming locale from headers instead of `context.locale`
26
22
 
27
- ## Stop Conditions
28
-
29
- - Stop if adding a new locale without confirming it exists in Sitecore and in next.config.js i18n.
30
- - Do not duplicate dictionary fetching without a clear need; prefer one fetch per request in the catch-all page.
31
-
32
- ## References
33
-
34
- - [AGENTS.md](../../../AGENTS.md) for Next.js i18n and getDictionary usage.
35
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
23
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,37 +1,24 @@
1
1
  ---
2
2
  name: content-sdk-editing-safe-rendering
3
- description: Ensures components render safely in XM Cloud editing and preview. Pages Router uses context.preview and context.previewData; use client.getPreview(context.previewData) or getDesignLibraryData(context.previewData) when in preview. Use when making components work in the Sitecore editor or fixing preview/editing behavior.
3
+ description: Preview/editing for Pages Router via context.preview and context.previewData in [[...path]].tsx.
4
4
  ---
5
5
 
6
- # Content SDK Editing-Safe Rendering (Pages Router)
6
+ # Editing-safe rendering (Pages Router)
7
7
 
8
- Ensure components behave correctly in XM Cloud editing, preview, and design library. This app uses **context.preview** and **context.previewData** in getStaticProps/getServerSideProps for editing data.
8
+ **Detail:** [AGENTS-router-specifics.md#routing-and-data-fetching](../../docs/AGENTS-router-specifics.md#routing-and-data-fetching)
9
9
 
10
- ## When to Use
10
+ ## When
11
11
 
12
- - User asks about editing, preview, design library, or "component not working in editor."
13
- - Task involves draft mode, editing chromes, or design library integration.
14
- - Fixing issues where components render differently or break in editor vs published.
15
- - User mentions getPreview, getDesignLibraryData, or editing API routes.
12
+ - Editing or preview broken
13
+ - Component must work in Page Editor or design library
16
14
 
17
- ## How to perform
15
+ ## Rules
18
16
 
19
- - In [[...path]].tsx getStaticProps/getServerSideProps: check context.preview; when true use isDesignLibraryPreviewData(context.previewData) to choose getDesignLibraryData vs getPreview; otherwise getPage + getDictionary + getComponentData. Editing routes: config uses EditingConfigMiddleware, render uses EditingRenderMiddleware, feaas/render uses FEAASRenderMiddleware; export handler as default.
17
+ - Use `context.preview` / `context.previewData` in getStaticProps/getServerSideProps
18
+ - When preview: `client.getPreview(context.previewData)` or `getDesignLibraryData(context.previewData)`
20
19
 
21
- ## Hard Rules
20
+ ## Stop
22
21
 
23
- - In the catch-all page (`src/pages/[[...path]].tsx`), use `context.preview` and `context.previewData`. When in preview, use `isDesignLibraryPreviewData(context.previewData)` to distinguish: if true, use `client.getDesignLibraryData(context.previewData)`; otherwise use `client.getPreview(context.previewData)`. When not in preview, use `getPage(path, { locale: context.locale })` then getDictionary and getComponentData as usual.
24
- - Do not assume editing/preview context in components that might run in static or non-editing contexts; guard on context.preview in getStaticProps/getServerSideProps.
25
- - Editing API routes: `src/pages/api/editing/config.ts` uses `EditingConfigMiddleware({ components, metadata }).getHandler()` (import components from `.sitecore/component-map`, metadata from `.sitecore/metadata.json`). `src/pages/api/editing/render.ts` uses `EditingRenderMiddleware().getHandler()`. `src/pages/api/editing/feaas/render.ts` uses `FEAASRenderMiddleware().getHandler()`. Export the handler as default. Do not duplicate client creation; config uses the same component map as the app.
26
- - Never commit editing secrets; use environment variables and document in .env.example only.
22
+ - Stop if changing preview flow would break editing API routes
27
23
 
28
- ## Stop Conditions
29
-
30
- - Stop and clarify if the issue is preview vs design library vs published; behavior differs.
31
- - Do not change proxy or middleware order to "fix" editing; editing is driven by API routes and context.previewData.
32
- - Do not recommend disabling secret validation without explicit user request and warning.
33
-
34
- ## References
35
-
36
- - [AGENTS.md](../../../AGENTS.md) for data fetching, preview flow, and editing routes.
37
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
24
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,36 +1,24 @@
1
1
  ---
2
2
  name: content-sdk-field-usage-image-link-text
3
- description: Renders Sitecore fields using SDK field components (Text, RichText, Image, Link) with proper validation and fallbacks. Use when rendering content fields or when the user mentions Text, RichText, Image, Link, or field components.
3
+ description: Renders Sitecore fields with SDK components Text, RichText, Image, Link.
4
4
  ---
5
5
 
6
- # Content SDK Field Usage (Pages Router)
6
+ # Field usage (Text, Image, Link) (Pages Router)
7
7
 
8
- Use SDK field components to render Sitecore fields with proper validation and fallbacks.
8
+ **Detail:** [AGENTS-router-specifics.md#component-map-and-layout](../../docs/AGENTS-router-specifics.md#component-map-and-layout)
9
9
 
10
- ## When to Use
10
+ ## When
11
11
 
12
- - User asks how to render a title, body, image, or link from Sitecore.
13
- - Task involves displaying content fields, fixing empty/broken images or links, or using RichText/Text/Image/Link components.
14
- - User mentions "field," "Image," "Link," "Text," "RichText," or "field value."
12
+ - Rendering Sitecore fields
13
+ - User mentions Text, RichText, Image, or Link
15
14
 
16
- ## How to perform
15
+ ## Rules
17
16
 
18
- - Use SDK field components: `<Text field={fields?.title} />`, `<RichText field={fields?.content} />`, `<Image field={fields?.image} />`, `<Link field={fields?.link} />`. Guard with `fields?.` when optional; use tag prop on Text when needed. Do not hardcode media or link URLs from Sitecore.
17
+ - Use `<Text>`, `<RichText>`, `<Image>`, `<Link>` from the SDK
18
+ - Validate field existence before render
19
19
 
20
- ## Hard Rules
20
+ ## Stop
21
21
 
22
- - Prefer SDK field components over manual field value extraction: `<Text field={fields?.title} />`, `<RichText field={fields?.content} />`, `<Image field={fields?.image} />`, `<Link field={fields?.link} />`. Use tag prop for Text when needed (e.g. tag="h1").
23
- - Validate or guard field existence before rendering when fields can be optional (e.g. `fields?.title`). Handle null/undefined and empty fields gracefully.
24
- - Do not hardcode image or link URLs when the data comes from Sitecore; use the field components or helpers that resolve media/URLs.
25
- - Follow the app's import pattern (e.g. from lib or components).
22
+ - Stop if bypassing SDK field components for user-controlled HTML without sanitization
26
23
 
27
- ## Stop Conditions
28
-
29
- - Stop if the field structure (name or type) is unknown; suggest checking the layout/data shape or asking the user.
30
- - Do not assume field names (e.g. "title") without confirmation when the template might use different names.
31
- - Do not commit or log raw field values that might contain PII or secrets.
32
-
33
- ## References
34
-
35
- - [AGENTS.md](../../../AGENTS.md) for component and Sitecore patterns.
36
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
24
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
@@ -1,38 +1,26 @@
1
1
  ---
2
2
  name: content-sdk-graphql-data-fetching
3
- description: Fetches page, dictionary, and component data via the single Sitecore client. Pages Router: getPage(path, { locale: context.locale }), getDictionary({ site: page.siteName, locale: page.locale }), getComponentData(page.layout, context, components); for SSG use getPagePaths(sites, context?.locales). Use when fetching page or dictionary content.
3
+ description: Page/dictionary fetch via SitecoreClient in [[...path]].tsx getStaticProps/getServerSideProps.
4
4
  ---
5
5
 
6
- # Content SDK GraphQL Data Fetching (Pages Router)
6
+ # Data fetching (Pages Router)
7
7
 
8
- All Sitecore data fetching goes through the single client in `src/lib/sitecore-client.ts`. Use getPage, getDictionary, and **getComponentData** in the catch-all page. Path from **extractPath(context)**; locale from **context.locale**.
8
+ **Detail:** [AGENTS-router-specifics.md#routing-and-data-fetching](../../docs/AGENTS-router-specifics.md#routing-and-data-fetching)
9
+ **Read first:** `src/pages/[[...path]].tsx`, `src/lib/sitecore-client.ts`
9
10
 
10
- ## When to Use
11
+ ## When
11
12
 
12
- - User asks how to fetch page data, layout, or dictionary phrases.
13
- - Task involves getPage, getDictionary, getComponentData, getPreview, getDesignLibraryData, or getPagePaths.
14
- - User mentions "sitecore client," "Layout Service," "page data," or "dictionary."
13
+ - Fetching page or dictionary data
14
+ - SSG paths or preview data
15
15
 
16
- ## How to perform
16
+ ## Rules
17
17
 
18
- - Use the client from `src/lib/sitecore-client.ts` only. In [[...path]].tsx: use `extractPath(context)` and `context.locale`; call getPage(path, { locale: context.locale }), then getDictionary and getComponentData(page.layout, context, components). For SSG use getPagePaths in getStaticPaths. For preview use context.preview and getPreview/getDesignLibraryData(context.previewData).
18
+ - Path from `extractPath(context)`; locale from `context.locale`
19
+ - `client.getPage(path, { locale })` then `getDictionary` and `getComponentData`
20
+ - SSG paths: `client.getPagePaths(sites, context?.locales)`
19
21
 
20
- ## Hard Rules
22
+ ## Stop
21
23
 
22
- - Use the single SitecoreClient instance in `src/lib/sitecore-client.ts`. Do not create a second client or instantiate SitecoreClient elsewhere.
23
- - **Path and locale:** Use `extractPath(context)` (from `@sitecore-content-sdk/nextjs/utils`) to get the path array; use `context.locale` for locale. Do not assume path or locale from elsewhere.
24
- - **Catch-all page flow:** In getStaticProps/getServerSideProps: `client.getPage(path, { locale: context.locale })`, then `client.getDictionary({ site: page.siteName, locale: page.locale })` and `client.getComponentData(page.layout, context, components)` for component props. Pass the result to the layout renderer.
25
- - **SSG:** In getStaticPaths, use `client.getPagePaths(siteNames, context?.locales || [])` where site names come from `.sitecore/sites.json` (e.g. `sites.map((s) => s.name)`). Use `revalidate` in getStaticProps for ISR.
26
- - **Preview:** Use `context.preview` and `context.previewData`; when in preview, use `client.getPreview(context.previewData)` or `client.getDesignLibraryData(context.previewData)`.
27
- - Config for the client comes from `sitecore.config.ts`; use environment variables, never hardcode secrets.
24
+ - Stop if fetching in client components when SSR/SSG is intended
28
25
 
29
- ## Stop Conditions
30
-
31
- - Stop if the task requires moving the client to another folder without clear requirement; suggest keeping a single instance in lib.
32
- - Do not add direct GraphQL or fetch to Layout Service bypassing the client unless the task explicitly requires it.
33
- - Do not fetch in _app; all data flows from [[...path]].tsx.
34
-
35
- ## References
36
-
37
- - [AGENTS.md](../../../AGENTS.md) for SitecoreClient, getPage, getDictionary, getComponentData, and SSG/SSR.
38
- - [Official Content SDK docs](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).
26
+ Docs: [Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html).