Problems with nested components - allow render arrays as slot values

Created on 14 January 2024, 6 months ago

Problem/Motivation

I am currently facing a lot of problems, when trying to nest components in Storybook - especially for components with slots/blocks. I tried different solutions like templates from string, a custom Twig function to render a component etc.

Unfortunately all of these lead to problems like block name collisions, double-escaped strings or unprocessed Twig markup in components deeper than level one in the embed tree.

Fortunately the SDC module allows render arrays for slot content, which would make it really easy to e.g. embed a component into another component via '#type' => 'component' render arrays (with unlimited nesting depth). But unfortunately the cl_server module is only able to handle string values for slots.

Steps to reproduce

  • Create a text component with a text slot for the actual text markup
  • Create a figcaption component with a text slot, where a text component should be included (or any another component)
  • Create a figure component with a caption slot, where a figcaption component should be included (or any another component)
  • Create appropriate Storybook stories for all these components, demoing the embed tree (figure component embeds figcaption component, which itself embeds text component) by using a similar syntax like in the example from the docs - but we cannot use {% include %} here due to the slots and have to use {% embed %} instead
  • This will lead to block name collision errors etc.

Proposed resolution

  • Allow render arrays in ServerEndpointController::generateRenderArray() (as they are already allowed by SDC module)

Remaining tasks

  • Create a patch/MR to introduce this feature

User interface changes

n/a

API changes

  • ServerEndpointController::render() controller will allow render arrays as slot values (which will also be handy to allow using '#type' => 'markup' render arrays for sending HTML code from Storybook to a component slot while avoiding duplicate escaping)

Data model changes

n/a

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany hctom

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024