netgen / ibexa-site-api

Site building productivity layer for the Ibexa CMS
https://netgen.io
GNU General Public License v2.0
1 stars 3 forks source link

Richtext with embed image causes infinite loop #32

Closed indebit closed 5 months ago

indebit commented 5 months ago

I'm using ibexa-site-api 6.1.2 with Ibexa 4.6.3.

Steps to reproduce: In admin area, within a richtext field, embed an image. Save and publish. The image is rendered correctly in admin preview.

On front-end, I'm trying to render that field using: {{ ng_render_field(content.fields.text_area) }} inside the template, but when I'm trying to check/visit in browser the page that contains that field, it keeps loading on and on in a infinite loop until the memory limit is hit.

I also tried with the Ibexa's default twig method and Ibexa's default Content type using: {{ ibexa_render_field(content.innerContent, 'text_area') }} but I get the same result => Infinite loop.

The only solution I've found so far, is to disable somehow the Netgen's functionality, according to the documentation, by adding this parameter in a yaml file:

bexa.site_access.config.default.ng_site_api.fallback_without_subrequest: false

Then, the page loads correctly and the richtext is rendered correctly as well.

I've checked the field's value in the database directly, and it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"
    xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0">
    <title ezxhtml:level="2">
        <emphasis role="strong">Title - online</emphasis>
        <emphasis role="strong"> und als App</emphasis>
    </title>
    <para> </para>
    <ezembed xlink:href="ezcontent://43910" view="embed" ezxhtml:class="ez-embed-type-image">
        <ezconfig>
            <ezvalue key="size">fullwidth</ezvalue>
        </ezconfig>
    </ezembed>
    <para>Text text <link xlink:href="ezurl://548" xlink:show="new"
            xlink:title="Text test">
            <emphasis role="strong">Testing</emphasis>
        </link>. Testing. </para>
    <para> </para>
    <eztemplate name="button" ezxhtml:class="ez-custom-tag ez-custom-tag--attributes-visible">
        <ezcontent>
            <para> </para>
        </ezcontent>
        <ezconfig>
            <ezvalue key="content">Test</ezvalue>
            <ezvalue key="internal_link">
                https://www.testing.com/testing</ezvalue>
            <ezvalue key="form">none</ezvalue>
            <ezvalue key="form_settings">none</ezvalue>
            <ezvalue key="color">white</ezvalue>
            <ezvalue key="align">center</ezvalue>
            <ezvalue key="width">auto</ezvalue>
        </ezconfig>
    </eztemplate>
    <para> </para>
</section>

As it can be seen, the embed element is defined in this XML content using ezembed tag. If I remove the entire ezembed code: `

fullwidth
</ezembed>`

after clearing the cache, the page loads correctly and the richtext field is rendered as expected. Of course, without the embed image. Then, if I put back the embed tag/element, the inifinite loop is happening again.

pspanja commented 5 months ago

Hi @indebit, thanks for the report!

Is Ibexa 4.6.3 you're using OSS version and is it a clean install or did you make any customizations? It would be useful if you could provide ng_site_api, ng_content_view and content_view configurations, so I can try to reproduce the problem.

indebit commented 5 months ago

Sure.

I'm using Ibexa 4.6.3 DXP Experience version. I've migrated an existing project (still with NetGen Site API) from eZ Platform 2.5 (to latest OSS, then to Headless, then to Experience). Added the new version of Netgen Site API (6.1.2), so existing functionality will still work.

These are the configuration:

ng_site_api:
    site_api_is_primary_content_view: true
ibexa:
    system:
        site:
            ng_content_view:
                mk_textblock:
                        template: '@ibexadesign/blocks/textblock.html.twig'
                        match:
                            Identifier\ContentType: mk_textblock

'/blocks/textblock.html.twig'

{{ ng_render_field(content.fields.text_area) }}

Basically, here I'm trying to render the richtext fields. I also tried to use the original Ibexa's method, but I got the same result:

{# {{ ibexa_render_field(content.innerContent, 'text_area') }} #}

I don't use any views from the original content_view. All the views I'm rendering, are made through ng_content_view.

I made some debugging and looks like the loop starts due to some Events within TraceableEventDispatcher (vendor/symfony/event-dispatcher\Debug\TraceableEventDispatcher.php) onpreProcess()`.

Please let me know if you need additional info

indebit commented 5 months ago

I think I found the loop:

Basically, these 2 events: ezpublish.pre_content_view and view.parameter_injection are switching on and on. See following screenshots:

Screenshot 2024-06-10 135639 Screenshot 2024-06-10 135837

pspanja commented 5 months ago

Thanks for the details, I'll try to reproduce this later today. Do you know if the same problem appeared on OSS as well?

indebit commented 5 months ago

I don't know, as I've only walked through OSS version to the final one (Experience) and didn't test on intermediary versions. Feel free to ask any additional info if you need, during your test later. Thanks for your support.

pspanja commented 5 months ago

I've successfully reproduced the problem, it happens on the clean OSS install whenever the fallback mechanism is used without subrequest, even without image embed.

Looking into it now, will let you know when I have something.

pspanja commented 5 months ago

I think I've found and fixed the problem. I made the fallback feature primarily for fallback from Ibexa to Site API, so it seems I've used a wrong View Builder (from Site API) for rendering Ibexa views and missed it because it only triggers for fallback from Site API to Ibexa.

This is now fixed in NGSTACK-904_view_fallback_fix branch, in commit https://github.com/netgen/ibexa-site-api/commit/691db39b55123b074057dcabfed63b6e70be01f2. It will be a bit awkward to release, since you use Site API 6.1.2 and Ibexa 4.6.3, and in Site API 6.1.4 there was a version limiting change introduced for a breaking change in Ibexa 4.6.5 (I think they don't consider it a part of BC promise). So I based the fix on Site API 6.1.2 and didn't made a pull request yet.

You should be able to install the fix from the branch, or, since the diff is quite small, you could patch the vendor directly. Can you test it out and let me know if it fixes the issue for you?

Also, is it an option for you to upgrade to Ibexa 4.6.7, so I can make the final fix in a single patch release?

indebit commented 5 months ago

The fix worked. Just for testing, I've patched the vendor directly. Will check which option would be the best, but I'm also able to upgrade to 4.6.7 if that's the best/easiest way.

Thank you for your support

pspanja commented 5 months ago

Yes, upgrading would be the best, and I think you shouldn't have any issues as the BC break I mentioned is in an internal part of the codebase that we're overriding here. I'll release it in 6.1.6 then :)

pspanja commented 5 months ago

Here it is: https://github.com/netgen/ibexa-site-api/releases/tag/6.1.6

@indebit thanks for reporting this!

indebit commented 5 months ago

Great news.

Thank you for taking care @pspanja