Command Palette

Search for a command to run...

Назад к скиллам
скилл № 84271

content-sdk-component-variants

Multiple presentations per component; regenerate maps after changes.

БесплатноБез исполняемых скриптов
Sitecoreот Sitecore★ 39 звёзд на GitHub

Установить content-sdk-component-variants в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Component variants (App Router + Cache Components)

Detail: AGENTS-router-specifics.md#component-maps-and-layout

When

  • Component variants or alternate renderings

Rules

  • Mirror existing variant patterns
  • Regenerate component maps

Lazy-loaded variants

Lazy (next/dynamic) components require self-managed component maps (see content-sdk-component-registration). withVariants (from @sitecore-content-sdk/nextjs) resolves all SXA variants (named exports) of a lazily loaded module.

Server components: register the dynamic() result in .sitecore/component-map.ts:

const Promo = dynamic(() => import('src/components/promo/Promo').then(withVariants));
// ...
['Promo', Promo],

Without withVariants, a single component entry (e.g. dynamic(() => import('src/components/promo/Promo'))) ignores FieldNames and always renders itself, so a variant it does not implement is not reported as MissingComponent.

Client components: Next.js bundles every Client Component imported by the server map with the page, so dynamic() in the maps does not load it on demand. Register a small 'use client' wrapper in both maps instead, and keep the variant code in a separate file:

// src/components/promo/Promo.tsx: small wrapper, the only part bundled with the page
'use client';
import dynamic from 'next/dynamic';
import { withVariants } from '@sitecore-content-sdk/nextjs';

const PromoLazy = dynamic(() => import('./PromoVariants').then(withVariants));

export const Default = PromoLazy;
export const Banner = PromoLazy;
// .sitecore/component-map.ts
import * as Promo from 'src/components/promo/Promo';
['Promo', { ...Promo, componentType: 'client' }],

// .sitecore/component-map.client.ts
import * as Promo from 'src/components/promo/Promo';
['Promo', { ...Promo }],
  • src/components/promo/PromoVariants.tsx exports the variants (Default, Banner, …); it is loaded on demand
  • Export every variant name from the wrapper, pointing to the same lazy component; withVariants renders the export matching rendering.params.FieldNames (unknown variant → MissingComponent)
  • Equivalent without withVariants: one dynamic() per variant in the wrapper, e.g. export const Banner = dynamic(() => import('./PromoVariants').then((mod) => mod.Banner));
  • New variant: add the export to the variants file and its name to the wrapper

Client-only rendering (ssr: false)

  • ❌ Never in .sitecore/component-map.ts or .sitecore/component-map.client.ts: both maps are imported on the server (editing config route), so the build fails with `ssr: false` is not allowed with `next/dynamic` in Server Components
  • ✅ Pass it to dynamic() in the 'use client' wrapper; all variants work:
    const PromoLazy = dynamic(() => import('./PromoVariants').then(withVariants), { ssr: false });
    

Stop

  • Stop if variant change breaks layout item without Sitecore update

Docs: Content SDK.

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл content-sdk-component-variants?

Multiple presentations per component; regenerate maps after changes.

Как установить скилл content-sdk-component-variants?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл content-sdk-component-variants запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить content-sdk-component-variants с