Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

Recursive calls to section with nested viewhelper yield unexpected results

Open georgringer opened this issue 9 months ago • 1 comments

Duplicate of https://forge.typo3.org/issues/88440, still confirmed in v14

Consider the following fluid template:

<f:section name="Test">
    <f:link.external uri="{testVar}">
        {testVar}
        <f:if condition="{testVar} == 'outer'">
            <f:render section="Test" arguments="{testVar: 'inner'}" />
        </f:if>
    </f:link.external>
</f:section>
<f:render section="Test" arguments="{testVar: 'outer'}" />

Normally, you would expect it to render as follows:

<a href="http://outer">
    outer
    <a href="http://inner">
        inner
    </a>
</a>

But it renders like this instead:

<a href="http://inner">
    outer
    <a href="http://inner">
        inner
    </a>
</a>

The reason seems to be that Fluid reuses view helper instances, so the two usages of f:link.external are effectively the same instance, overwriting the arguments.

Do note that the f:link.external is just an example and obviously does not make much sense (in practical terms), but it was just one of the few view helpers that wrap something (condition for this bug to trigger - the recursive call has to be inside the viewhelper content) that I found in core fluid. I usually encounter this issue when rendering menus recursively.

georgringer avatar Mar 30 '25 09:03 georgringer

Thanks! I was able to reproduce it in a test. Currently, cached templates behave correctly, but uncached templates have the unwanted behavior you describe.

s2b avatar May 19 '25 09:05 s2b