Files
ipal-kit/docs/blocks.md
T
Radosław SmolińskiandClaude Opus 5.5 2d9f3e15d4 Docs in English (part 1), seeding guide, Coolify deployment
- Translate to English every doc the code branches did not touch: AGENT.md,
  developer guide, vibe, CHANGELOG, docs index, module pages, all skills
  except ipal-seo-check (14 pages follow after the security/SEO merge).
  Placeholder marker is now [TO FILL: …]; skill resources renamed to
  section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer
  block say the docs are in English.
- docs/seeding.md: create-only, natural keys, never delete, no users or
  secrets, empty-field globals, fallbackLocale: false, dry run, backup and
  restore, production update guard, seeds vs migrations, Coolify Terminal.
  Seed templates gain --dry-run, the SEED_UPDATE production guard
  (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary.
  "Seeding on production" rule block in AGENT.md.
- Coolify is the single deployment path (deployment, env, developer guide,
  ipal-setup): build vs runtime env, migrations on container start
  (prodMigrations), health check and rolling updates, rollback, backups and
  restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone;
  default is media served by the app (R2_PUBLIC_URL empty).
- docsConsistency: no Polish prose outside code/quoted data (pending pages
  listed); IPAL_* names may also be read by shipped skill templates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:39:03 +02:00

5.0 KiB

blocks

RenderBlocks — a generic, server-side block rendering engine. The plugin does not know your blocks: it iterates over the data, maps blockType → component through a registry (prop), handles nesting and per-block extensions. You define the blocks (schema + components) in your project.

Config

No options in payload.config — you define blocks in your collections (a blocks type field). The plugin provides only the rendering engine.

⚠️ Do NOT write your own block renderer (switch)

The block renderer is RenderBlocks from the plugin — NEVER your own switch/if. Common mistake: the project writes its own BlockRenderer with switch (block.blockType) and 20 cases. That breaks A0 — the plugin has the engine, the project provides only the component MAP.

// WRONG — own switch in the project (verbose, no enhanceProps, grows linearly)
switch (block.blockType) {
  case 'hero': return <Hero {...block} />
  case 'faq': return <FAQ {...block} />
  // ...20 cases
}

// RIGHT — map + RenderBlocks (engine from the plugin)
const registry = { hero: Hero, faq: FAQ, /* ... */ }
<RenderBlocks blocks={page.layout} components={registry} />

Why RenderBlocks, not a switch: enhanceProps (nav anchors, etc.), guards, nesting support, consistency across projects. A switch has none of this and grows with every block. The map is flat and declarative.

Front — RenderBlocks

Import from @intecion/ipal-kit/rsc (it is a server component):

import { RenderBlocks } from '@intecion/ipal-kit/rsc'

// Your registry: blockType → component (the components are yours)
import { Hero } from '@/blocks/Hero'
import { FormBlock } from '@/blocks/FormBlock'

const registry = { hero: Hero, formBlock: FormBlock }

export default async function Page() {
  const page = await payload.findByID({ collection: 'pages', id })
  return <RenderBlocks blocks={page.layout} components={registry} />
}
  • unknown blockType → skipped (null), does not crash
  • blocks empty / null → null
  • nested blocks: the parent component renders <RenderBlocks> itself and imports the registry itself — the engine does NOT pass the map in props (functions do not cross the server→client boundary in RSC)

enhanceProps — per-block logic without the plugin knowing

When a block needs data from other blocks (e.g. a nav collecting anchors from sections), pass enhanceProps. The plugin calls it without knowing your blocks:

// arguments: { block, allBlocks, index }
const enhanceProps = ({ block, allBlocks }) => {
  if (block.blockType !== 'sectionNav') return {}
  const sections = allBlocks
    .filter((b) => b.blockType === 'anchoredSection')
    .map((b) => ({ anchor: b.anchor, label: b.navLabel }))
  return { _sections: sections }
}

<RenderBlocks blocks={page.layout} components={registry} enhanceProps={enhanceProps} />

Shared section fields — buildSectionHeaderField, buildSectionSettingsField

import { buildLinksField, buildSectionHeaderField, buildSectionSettingsField } from '@intecion/ipal-kit'

fields: [
  buildSectionHeaderField(),        // `header` group: eyebrow, heading, intro (localized) — type SectionHeaderData
  …block fields…,
  buildLinksField(),
  buildSectionSettingsField(),      // `settings` sidebar: anchor, background — type SectionSettings
]

Default: header (interface SectionHeaderData), settings in the sidebar (interface SectionSettings) with anchor and background (default / muted / inverted, the first value by default). Everything can be changed: buildSectionSettingsField({ backgrounds: [{ label: 'Brand', value: 'brand' }], anchor: false, fields: [{ name: 'spacing', … }] }), backgrounds: false (no background choice), buildSectionHeaderField({ name, fields, interfaceName }). The project maps the background values to its <Section> classes. The data shape matches the former src/fields/sectionHeader.ts / sectionSettings.ts from section-code.md — swapping the import needs no migration.

Block component

Each component gets the block data as props (plus whatever enhanceProps returns; in createPageRoute also locale, isFirst and blockProps — frontend.md). Spacing/layout are yours — the engine does not wrap blocks in any markup.

export function Hero(props) {
  return <section className="py-16">{/* ... */}</section>
}

Types: BlockComponentMap, BlockData, EnhanceProps, RenderBlocksProps (/rsc), SectionHeaderFieldOptions, SectionSettingsFieldOptions (root).

Turn off, override, extend

  • The module has no options in ipalKit() — it adds nothing to the schema; you either use RenderBlocks or not.
  • The project keeps the component map and the block schemas; add per-block logic through enhanceProps.
  • buildSectionHeaderField / buildSectionSettingsField: name, fields (extra fields), interfaceName, anchor: false, backgrounds: […] | false.
  • The engine does not wrap blocks in markup and has no wrapper option — the project component does the wrapping.