False positive when checking empty slots

Created on 10 May 2025, 28 days ago

Problem/Motivation

In UI Suite Bootstrap, in the table component, there is:

  {% if caption %}
    <caption>{{ caption }}</caption>
  {% endif %}

The table presenter template is passing an empty string as the caption variable.

But in the component template I have an array with an empty #children.

In ui_patterns/src/Plugin/UiPatterns/PropType/SlotPropType.php, there are 2 problematic places :

    if (is_string($value)) {
      return ['#children' => Markup::create($value)];
    }

After making the proposed change I obtain an empty array with #cache from:

protected static function cleanRenderArray(array $value): mixed {
    if (empty($value)) {
      // Element::isRenderArray() returns FALSE for empty arrays.
      return ['#cache' => []];
    }

Steps to reproduce

Using UI Suite Bootstrap, create a View using a table display.

Proposed resolution

    if (is_string($value) && !empty($value)) {
      return ['#children' => Markup::create($value)];
    }

I don't know what to do about the other place where there is a problem.

Remaining tasks

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

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

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡ΊπŸ‡¦Ukraine SmovS Lutsk
  • Merge request !386#3523756 - Added a check on not empty value. β†’ (Open) created by SmovS
  • Pipeline finished with Success
    14 days ago
    Total: 534s
    #505584
  • πŸ‡ΊπŸ‡¦Ukraine SmovS Lutsk

    Hi @grimreaper
    I have added a check for a non-empty value according to your proposal.

    But I'm still confused about this false positive when checking slots.
    E.g. I set the caption in the table with wysiwig source with an empty textarea.

    In this case, the table contains an empty caption tag because wysiwig source creates an array with text format settings.
    It would be cleaned by self::cleanRenderArray(), but didn't

    I am not sure if it is related to the false positive that you mentioned. Probably I went the wrong way.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Hi @smovs,

    The problem occurs for example when using the table component with the views table presenter template.

    If you are using a component "manually" or with site building it is ok.

    But with a presenter template, like written in the issue summary, you can get an empty string as slot value and in this case the problem occurs.

    So, to test you can create a view using the table display (not component display using the table component).

Production build 0.71.5 2024