Skip to content

"each_row" helper cannot contain calls to inline partials. #846

Closed

Description

@mesr

Introduction

"each_row" helper cannot contain calls to inline partials.

To Reproduce

{{#*inline "item" }}
    <li>{{ this }}</li>
{{/inline}}
<ul>
{{#each_row }}
    {{> item }}
{{/each_row }}
</ul>
select
    'foo' as component;
select
    'a' as item;
select
    'b' as item;
select
    'c' as item;

Actual behavior

After following these steps, this error message shows up on the web page:

Partial not found item

Version information

  • OS: Linux Debian 11
  • PostgreSQL 17
  • SQLPage 0.33.1

Activity

  1. added
    bug
    on Mar 6, 2025
  2. lovasoa commented on Mar 6, 2025

    @lovasoa
    Collaborator

    The issue you're experiencing with inline partials not working inside each_row helpers is due to how SQLPage processes templates internally.

    In SQLPage the template rendering process involves splitting templates into three parts:

    pub struct SplitTemplate {
        pub before_list: Template,
        pub list_content: Template,
        pub after_list: Template,
    }

    When SQLPage encounters an each_row helper, it splits the template at that point using the split_template function. This function extracts the content inside the each_row block into a separate template (list_content), with everything before it going into before_list and everything after into after_list.

    The problem occurs because inline partials defined with {{#*inline "name"}}...{{/inline}} are registered in the Handlebars registry during the initial template parsing. However, when the template is split, these inline partial definitions remain in the before_list section, but the list_content template (which contains your each_row content) becomes a separate template context that doesn't have access to those inline partials.

    In the render_item method of SplitTemplateRenderer, when it tries to render each row, it's using the isolated list_content template which can't see the inline partials defined in the parent template.

    This is why you're seeing the "Partial not found item" error - the {{> item }} reference inside your each_row block is looking for a partial that isn't accessible from that context.

    Possible workarounds:

    1. Use direct HTML in the each_row block instead of a partial
    2. Define the partial inside #each_row

    This is a limitation of how SQLPage processes templates to support its streaming row-by-row rendering model, which is different from standard Handlebars processing.

  3. mesr commented on Mar 7, 2025

    @mesr
    Author

    Thank you @lovasoa for this detailed answer. This is very useful information indeed. Workaround 1 is not applicable to our use case, as it would lead to a lot of hard-to-maintain duplication of code. Workaround 2, even though not ideal, is a workable solution. So, thanks again and keep up the good work!

  4. 81reap commented on Oct 29, 2026

    @81reap
    Collaborator

    I think this is still an issue

    reproduction

    $ cat tests/end-to-end/fixtures/repro_846/index.sql 
    SELECT 'text' AS component, 'repro' AS contents;
    
    $ cat tests/end-to-end/fixtures/repro_846/page.sql 
    SELECT 'repro_846' AS component;
    SELECT 'a' AS item;
    SELECT 'b' AS item;
    
    $ cat tests/end-to-end/fixtures/repro_846/test.ts 
    import { expect, test } from "../../fixture.ts";
    
    test("each_row calls an inline partial", async ({ page }) => {
      await page.goto("/repro_846/page.sql");
      await expect(page.locator(".item")).toHaveCount(2);
    });
    repro_846 postgres
    v0.33.0 ✘ failed
    v0.47.0 ✘ failed
    tree ✘ failed

    On commit 616df27: nix run .#reproduce -- repro_846 postgres v0.33.0 v0.47.0 tree

  5. added a commit that references this issue on Oct 30, 2026
    eb6ef5a
  6. added a commit that references this issue on Oct 30, 2026
    f1c714a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions