Skip to content

[5.x]: Revision previews do not render nested elements when loaded via eagerly() #18693

@superflausch

Description

@superflausch

What happened?

Description

When viewing an entry revision and opening its tokenized preview URL, rendered template content is missing nested elements that are loaded via eagerly().

The same content loads correctly when viewing the current entry or a draft preview URL. The issue only seems to occur when previewing a revision. I also confirmed that removing the eagerly() query method resolves the issue and the nested content is rendered as expected.

The following does not work correctly in a revision preview, because childBlocks ends up empty:

{% set sections = entry.sections ?? null %}

{% for section in sections %}
    <h3>SECTION</h3>
    
    {% set childBlocks = section.blocks.eagerly().all() ?? null %}

    {% for block in childBlocks %}
        <h4>{{ block.type.handle|upper }} BLOCK</h4>
    {% endfor %}
{% endfor %}

If I remove eagerly() and call section.blocks.all() instead, the nested elements are shown correctly in the revision preview as well.

We noticed this on an active project and were also able to reproduce it on a simple test setup.

Steps to reproduce

  1. Create a content model like this:
    Pages (Section) → Page (Entry Type) → Sections (Matrix field, "Cards" view mode) → Section (Entry Type) → Blocks (Matrix field, "Blocks" view mode) → Block (Entry Type)
  2. Set up a template for the Pages section similar to the example above.
  3. Create a Page entry with nested elements:
    Sections → Section → Blocks → Block
  4. Save additional revisions of the entry.
  5. Open a revision of the entry.
  6. Access the rendered template via the View action.
  7. Notice that nested content is missing when eagerly() is used in the template.

Expected behavior

The template should render the same content regardless of whether the preview is for the current entry, a draft, or a revision.

Actual behavior

Nested content loaded via eagerly() is missing when previewing a revision.

Craft CMS version

5.9.19

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions