fluid-components icon indicating copy to clipboard operation
fluid-components copied to clipboard

Recursive calls not possible

Open infabo opened this issue 3 years ago • 1 comments

In classic Fluid with sections/partials you can do recursive calls.

Example:

<f:render section="Test" arguments="{foo: 1}"/>

<f:section name="Test">
    Hello World
    <f:if condition="{foo} === 1">
        <f:render section="Test" arguments="{foo: 0}"/>
    </f:if>
</f:section>

This would print:

Hello World Hello World

But you can't do alike with components.

Given you have a component called Button (c:atom.button) with an impossible condition:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
      xmlns:fc="http://typo3.org/ns/SMS/FluidComponents/ViewHelpers"
      data-namespace-typo3-fluid="true">
<fc:component>
    <fc:param name="link" type="Typolink"/>
    <fc:param name="label" type="string"/>
    <fc:param name="target" type="string" default="_self" optional="1"/>
    <fc:param name="style" type="string" default="primary" optional="1" description="<primary|secondary|alternate>"/>

    <fc:renderer>
       <f:link.typolink class="button button--{style}" parameter="{link}" title="{label}" target="{target}" additionalAttributes="{role: 'button'}">
           <span class="button__text">{label}</span>
       </f:link.typolink>
        <f:if condition="1 == 2">
            <c:atom.button link="{link}" label="foo"/>
        </f:if>
    </fc:renderer>
</fc:component>
</html>

Leads to:

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/typo3fluid/fluid/src/Core/Parser/TemplateParser.php on line 661

In runs into a endless recursion.

infabo avatar Feb 15 '22 16:02 infabo

I left a comment in the other issue:

Hi everyone, and thank you for bringing this to our attention. That's probably a tough one to fix, but we should at least look into it if it's solvable by the extension.

One possible workaround that could work is to enable the somewhat hidden partials feature introduced with https://github.com/sitegeist/fluid-components/pull/65 and try to use partials for the recursive part. If you set the TYPO3 feature flag fluidComponents.partialsInComponents, you should be able to try this.

So yes, this is a bug, but it's probably complicated to fix. However, any help or ideas are appreciated.

s2b avatar Apr 29 '22 10:04 s2b