Skip to content

@partial-block interacting strangely with identical helper blocks. #1186

@damncabbage

Description

@damncabbage

The minimal test case:

{{#*inline "test"}}
  <div>{{> @partial-block }}</div>
{{/inline}}

{{#>test }}
  {{#each listOne as |item|}}
    <p>{{ item }}</p>
  {{/each}}
{{/test}}

{{#>test }}
  {{#each listTwo as |item|}}
    <p>{{ item }}</p>
  {{/each}}
{{/test}}

With this input:

{ 
  listOne: ["abc", "def"],
  listTwo: ["123", "zxy"]
}

Produces this error and stack-trace under Handlebars 4.0.5 (also a confirmed bug via the 4.0.3 tryhandlebarsjs.com REPL):

TypeError: Cannot read property '0' of undefined
    at eval (eval at createFunctionContext (…/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:27), <anonymous>:8:167)
    at prog (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:224:12)
    at execIteration (…/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:51:19)
    at Object.<anonymous> (…/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:61:13)
    at eval (eval at createFunctionContext (…/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:261:27), <anonymous>:14:31)
    at prog (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:224:12)
    at Object.invokePartial (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:273:12)
    at Object.invokePartialWrapper [as invokePartial] (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
    at Object.eval (eval at createFunctionContext (…/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:261:27), <anonymous>:6:28)
    at main (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)

I think the summary for this bug is:

  • The last block,
  • … in a run of identical helper blocks (eg. the contents in between the {{#each ...}} {{/each}} pairs)
  • … that occur within a @partial-block-using wrapper partial
  • … will explode.

(To be clear, the example I hit this with does not use in-line partials; I'm only using them here to get a smaller example. The error occurs both with and without the use of them.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions