Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack blown when nested "@partial-block"-using partial not given a partial block. #1185

Closed
damncabbage opened this issue Feb 18, 2016 · 10 comments

Comments

@damncabbage
Copy link

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.

@stringbean
Copy link

This also affects inline partials. JSFiddle showing this.

@jaichandra
Copy link

jaichandra commented May 2, 2016

Nested partials is critical to building modular templates. This needs to be addressed on priority. Any workarounds?

@damncabbage
Copy link
Author

damncabbage commented May 3, 2016

@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.)

@jaichandra
Copy link

jaichandra commented May 3, 2016

@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?

@damncabbage
Copy link
Author

@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}}

lawnsea added a commit to lawnsea/handlebars.js that referenced this issue Aug 17, 2016
@lawnsea
Copy link
Collaborator

lawnsea commented Sep 10, 2016

@damncabbage I believe that #1243 fixes this bug as well.

@Dangoo
Copy link

Dangoo commented Sep 12, 2016

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

@lawnsea
Copy link
Collaborator

lawnsea commented Sep 12, 2016

@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.

@Dangoo
Copy link

Dangoo commented Sep 13, 2016

@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… 😛 )?

lawnsea added a commit to lawnsea/handlebars.js that referenced this issue Nov 9, 2016
lawnsea added a commit that referenced this issue Nov 11, 2016
@nknapp
Copy link
Collaborator

nknapp commented Dec 30, 2016

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 #1185 (comment) is not on your side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants