0

I'm working on a Jekyll site and encountering a "Nesting too deep" error when trying to render nested comments using a recursive include. Here's a simplified version of my template:

{% comment %}
  Filename: comment.liquid
  Comment template - displays a single comment and its nested replies
{% endcomment %}

<div class="px-0 text-sm">
  <div class="mb-1">
    <a href="#" class="text-text-muted no-underline text-sm leading-none inline-block pt-0.5 hover:text-link-hover">▲</a>
    <small class="text-text-muted ml-2 text-sm">@{{ comment.author }}</small>
    <small class="text-text-muted ml-2 text-sm">{{ comment.date | date: "%b %d, %Y" }} | <a href="#" class="ml-2 text-xs text-primary hover:underline">parent</a> | <a href="#" class="ml-2 text-xs text-primary hover:underline">next</a></small>
  </div>
  <div>
    <p>{{ comment.content }}</p>
    <small class="text-right underline text-xs cursor-pointer mt-1 inline-block">reply</small>
  </div>

  {% assign replies = site.comments | where: "parent", comment.slug | sort: "date" %}
  <div>comment_slug: {{ comment.slug }}</div>

  {% for reply in replies %}
    <div class="ml-2 mt-4 border-l-2 border-gray-200 pl-2 text-sm md:pl-4">
      <div>parent: {{ reply.parent }}</div>
      <div>slug: {{ reply.slug }}</div>
      <div>content: {{ reply.content }}</div>
      <!-- Error occurs here -->
      {% include comment.liquid comment=reply %}
    </div>
  {% endfor %}
</div>

The comments are stored in _comments/, and the structure looks something like this:

_comments/
├── comment1.md
├── comment1_reply1.md
├── comment2.md
├── comment3.md
├── comment4.md
├── comment4_reply1.md
├── comment4_reply1_reply1.md
├── comment4_reply1_reply1_reply1.md
├── comment4_reply1_reply1_reply1_reply1.md
├── comment4_reply1_reply1_reply1_reply1_reply1.md
└── comment4_reply1_reply1_reply1_reply1_reply1_reply1.md

Each comment can have a parent field linking to another comment's slug, but the replies go several levels deep (up to 6–7 layers).

Problem:
When rendering a post that includes deeply nested comments, Jekyll throws an error:

Nesting too deep - included in /_layouts/post.liquid

Questions:

  • Why is this happening, even if the data structure looks normal?
  • Is there a way to avoid or fix the "nesting too deep" error?
  • Would a different approach to rendering nested comments in Jekyll (without hitting this recursion limit) be better?

1 Answer 1

1

Are you sure the data structure is fine? Have you confirmed with {{site|jsonify}}?

I would have assumed, without plugins, your tree would look more like: comment4/reply1/reply1/reply1/reply1/reply1/index.md

_comments
└── comment4
    ├── index.md
    └── reply1
        ├── index.md
        └── reply1
            ├── index.md
            └── reply1
            ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.