Skip to content

Async Shortcodes fail when used inside loop-included nunjuck templates #4210

@Seramis

Description

@Seramis

Operating system

Fedora 42 KDE

Eleventy

3.1.2

Describe the bug

Define an async shortcode:

eleventyConfig.addAsyncShortcode("testShortcodeAsync", async function () {
    return "Value from async shortcode";
});

Create a main test file main.njk:

<h2>Test2</h2>

{% set data = [1, 2, 3] %}
{% for item in data %}
    <p>Item {{ item }}</p>
    <p>{% include "./subpage.njk" %}</p>
    <hr/>
{% endfor %}

Create a subpage.njk file, that calls async shortcode:

Yay!

{% testShortcodeAsync %}

Expected result something like:

Item 1
Yay! Value from async shortcode
---
Item 2
Yay! Value from async shortcode
---
Item 3
Yay! Value from async shortcode
---

Actual result something like this:

Item 1

Item 2

Item 3

It seems to be quite broken. Not only isn't the subpage.njk content rendered, it breaks the whole loop iteration, as the <hr/> is also missing, that comes from the main.njk.

For the longest time I was thinking I just am not able to understand how the shortcodes work. Until I now dug in thoroughly to figure out what am I doing wrong - seems that I really stumbled on a nasty bug.

Reproduction Source Code URL

No response

Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions