Variant in prop names conflict with variant in SDC definition

Created on 1 September 2025, about 1 month ago

Hello, after some digging finally found what was killing our website render when using the dsfr4drupal components.

Problem/Motivation

When we are using a component in a render array (leveraging core/lib/Drupal/Core/Render/Element/ComponentElement.php) if our SDC as a prop named "variant" it will conflict with global variants implemented in 11.2.0 https://www.drupal.org/node/3517062 β†’ .

To be specific, this particular piece of code introduce an unwated behaviour (L53-56) :

    $props = $element['#props'];
    if (isset($element["#variant"]) && !isset($props['variant'])) {
      $props['variant'] = $element["#variant"];
    }

Moreover, if no variants are defined #variant default to empty string "", meaning that our prop will get "" as prop value. Which breaks our DSFR4Drupal components (and crash the website, as "" is not a valid variant).

Steps to reproduce

Create a renderable array of a dsfr4drupal sdc component with a "variant" prop (like card component) and omit the enum prop "variant" (sm/lg).

Proposed resolution

Rename all variant props as "cardVariant"/"buttonVariant" etc... Which will needs refactoring :(

Regards,

πŸ› Bug report
Status

Active

Version

1.4

Component

Code

Created by

πŸ‡«πŸ‡·France plits

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

Comments & Activities

  • Issue created by @plits
  • πŸ‡«πŸ‡·France S3b0uN3t Nantes

    Hello,
    This behavior change was specifically planned for 1.4.4 by systematically defining a default value for each "variant" property. To reproduce this bug, could you provide a concrete example (with the values ​​for the props used)?

    Regards

  • πŸ‡«πŸ‡·France plits

    Salut s3b0un3t :)

    Attached module to reproduce issue against 1.4.4

    drush en component_debug -y

    Navigate to /component-debug/button =>

    Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("[dsfr4drupal:button/variant] Does not have a value in the enumeration ["secondary","tertiary"]. The provided value is: "".") in "dsfr4drupal:button" at line 1. in Twig\Template->yield() (line 1 of themes/contrib/dsfr4drupal/components/button/button.twig).

    Thanks !

  • πŸ‡«πŸ‡·France S3b0uN3t Nantes

    Thanks for your feedback. I’m currently in vacation without computer.

    I have forwarded the issue to the other maintainers to look it soon.

  • πŸ‡«πŸ‡·France S3b0uN3t Nantes
Production build 0.71.5 2024