I just hit this in the wild with someone accidentally calling a @partial-block-using partial without giving it said partial block.
Minimal example:
var Handlebars = require('handlebars');
Handlebars.registerPartial('outer', '<p>{{> @partial-block }}</p>');
Handlebars.registerPartial('inner', '<span>{{> @partial-block }}</span>');
// Calls "inner" without giving it a partial block.
Handlebars.compile("<div>{{#>outer}} {{>inner}} {{/outer}}</div>")();
Produces:
RangeError: Maximum call stack size exceeded
at Object.eval (eval at createFunctionContext (…/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:1:10)
at main (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:32)
at ret (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:176:12)
at ret (…/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:525:21)
at Object.invokePartial (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:268:12)
at Object.invokePartialWrapper [as invokePartial] (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
at eval (eval at createFunctionContext (…/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:254:23), <anonymous>:6:28)
at prog (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:219:12)
at Object.invokePartial (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:268:12)
at Object.invokePartialWrapper [as invokePartial] (…/node_modules/handlebars/dist/cjs/handlebars/runtime.js:68:39)
As far as I can tell: the inner partial, when not giving a partial-block of its own, will refer to the @partial-block given to the outer partial.
Tested with Handlebars 4.0.5.
This also affects inline partials. JSFiddle showing this.
Nested partials is critical to building modular templates. This needs to be addressed on priority. Any workarounds?
@jaichandra: I think there may be some confusion: this bug is triggered by accidentally not providing a needed partial-block when calling a partial; in this case, Handlebars goes and uses a different partial-block.
It should result an error in all cases, just not this error.
(Nested partials, when called correctly, work fine; there shouldn't be a need for a workaround.)
@damncabbage: Ok. May be im confused. Here is an example of what I am trying to do.
item.hbs
<div class="item-text">
{{> @partial-block}}
</div>
list-item.hbs
<div class="list-item">
{{#> item}}
{{> @partial-block}}
{{/item}}
</div>
usage:
{{#> list-item}}
<span>Item name</span>
{{/list-item}}
I got RangeError: Maximum call stack size exceeded error.
Does this work?
@jaichandra: I'm treating these as separate bug reports (same symptom, but no idea if it's the same cause), but yes, your example breaks for me with latest-stable.
My all-inline-partials example for ease:
{{#*inline "outer" }}
{{#>inner}}
<p>{{> @partial-block }}</p>
{{/inner}}
{{/inline}}
{{#*inline "inner" }}
<div>{{> @partial-block }}</div>
{{/inline}}
{{#>outer}}
Hello
{{/outer}}
@damncabbage I believe that #1243 fixes this bug as well.
After building the sources and integrating the version built from 7535e48 I get this error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: The partial @partial-block could not be found
at Object.invokePartial (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/runtime.js:255:11)
at Object.invokePartialWrapper [as invokePartial] (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/runtime.js:65:39)
at Object.eval (eval at createFunctionContext (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:252:23), <anonymous>:14:28)
at main (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/runtime.js:170:32)
at Object.ret (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/runtime.js:173:12)
at Object.lsg-demo-section (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:467:21)
at Object.invokePartialWrapper [as invokePartial] (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/runtime.js:69:46)
at eval (eval at createFunctionContext (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:252:23), <anonymous>:5:31)
at prog (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/runtime.js:206:12)
at execIteration (<PROJEKT_ROOT>/node_modules/handlebars/dist/cjs/handlebars/helpers/each.js:42:19)
/cc @lawnsea @wycats
@Dangoo do you get this error with one of the templates from this issue? If not, please post a template the reproduces the error you're seeing.
@lawnsea No, the given examples work flawlessly.
The error is caused by a custom helper in our project (Styleguide-Thingy) wich injects the generated markup inside a markup tab (using @partial-block).
Sometimes the output of that generator is empty so my first guess was that this would cause the error.
But using @damncabbage example while leaving the content of {{#>outer}} empty produces no error - as expected.
The strange thing is, that it worked with 4.0.5 and breaks with the master state.
But I believe it's likely an issue on our side.
May you please tag/publish a new release then (compiling the master each time is no fun… 😛 )?
I just verified that this issue is fixed in 4.0.6 (the original issue). @Dangoo Could you open a new issue if the error you wrote about in https://github.com/wycats/handlebars.js/issues/1185#issuecomment-246627746 is not on your side?
Most helpful comment
@damncabbage: Ok. May be im confused. Here is an example of what I am trying to do.
item.hbs
list-item.hbs
usage:
I got
RangeError: Maximum call stack size exceedederror.Does this work?