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,

CommentFileSizeAuthor
#3 component_debug.zip2.07 KBplits

Comments

plits created an issue. See original summary.

s3b0un3t’s picture

Status: Active » Postponed (maintainer needs more info)

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

plits’s picture

StatusFileSize
new2.07 KB

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 !

s3b0un3t’s picture

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

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

s3b0un3t’s picture

Status: Postponed (maintainer needs more info) » Needs work
benjy44’s picture

Assigned: Unassigned » benjy44

s3b0un3t’s picture

Assigned: benjy44 » s3b0un3t
Status: Needs work » Needs review
s3b0un3t’s picture

Status: Needs review » Fixed

After changes, the following behaviors can be noted:

  1. The variant is no longer limited in terms of value (the enumeration has been removed)
  2. No change when rendering component in Twig
  3. Rendering component by render array:
  4. Before Drupal core 11.2.0:
    • The variant declaration in "#props" is taken into account.
    • The variant declaration in "#variant" is not taken into account.
  5. From Drupal core 11.2.0:
    • No more error when no variant is present.
    • The variant declaration in "#variant" is taken into account.
    • The variant declaration in "#props" is taken into account (and takes precedence over "#variant").

It seems OK!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

s3b0un3t’s picture

Status: Fixed » Closed (fixed)

Fixed into release 1.5.0

plits’s picture

Thanks :)