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

Inline partials "leak" - another scenario #539

Closed
dudabone opened this issue Sep 20, 2016 · 4 comments
Closed

Inline partials "leak" - another scenario #539

dudabone opened this issue Sep 20, 2016 · 4 comments
Labels
Milestone

Comments

@dudabone
Copy link

dudabone commented Sep 20, 2016

Hi @jknack. Thanks for the fix of issue #523, it indeed resolved the scenario I have described. However, I ran into a different scenario in which this issue still happens. This time we have two inline partials, in the second we call another template. Setup is as follows:

main.hbs:

main has partials:<br>
-------------<br>
{{>inherit1}}
-------------<br>
{{>inherit2}}

with the following partials:

base.hbs:

text from base partial<br>
{{#>inlinePartial}}{{/inlinePartial}}<br>
{{#>inlinePartial2}}{{/inlinePartial2}}<br>

inherit1.hbs:

inherit1<br>
{{#>base}}
{{#*inline "inlinePartial"}}
    inline partial defined by inherit1, called from base
{{/inline}}
    {{#*inline "inlinePartial2"}}
        {{>some-other-template}}
    {{/inline}}
{{/base}}

inherit2.hbs:

inherit2<br>
{{#>base}}
{{/base}}

some-other-template.hbs:

template called from second inline partial of inherit 1

The expected result is:

main has partials:

inherit1
text from base partial
inline partial defined by inherit1, called from base
template called from second inline partial of inherit 1

inherit2
text from base partial

Actual result:

main has partials:

inherit1
text from base partial
inline partial defined by inherit1, called from base
template called from second inline partial of inherit 1

inherit2
text from base partial
inline partial defined by inherit1, called from base

Again, the line "inline partial defined by inherit1, called from base" has "leaked" from inherit1.hbs to inherit2.hbs. I will continue trying to debug the code by myself but I can't promise anything :) as I am not yet completely familiar with the project's code. Will be great if you could take a look.

@dudabone
Copy link
Author

Adding the files in the example above, in case you find it useful.
inline_partials_leak2.zip

@dudabone
Copy link
Author

Hi @jknack,

While debugging this scenario, I noticed a few behaviors that I am not quite sure I understand:

  1. The "inlinePartial" block defined in inherit1.hbs is available for "some-other-template.hbs" when it is called from "inlinePartial2". From what I see, this is not the case when rendered in handlebars.js.
  2. "Normal" partials (not inline, such as "some-other-template.hbs") are assigned with "Partial.java" class, which is the same class that inline partials are assigned, causing both to run the "before" and "after" methods and adding a new entry to the Context.INLINE_PARTIALS map. Not sure this should be the use case for "some-other-template.hbs"?
  3. Generally speaking, I see the Context.INLINE_PARTIALS is registered on the root context (context.data), whereas in handlebars.js the inline partials are registered on the local context of the template. In Handlebars.java this makes it hard for the code to know which templates should have access to which inline partials.

I would really love to contribute a fix to this issue, however, I was not able to think of anything simple enough that would not involve breaking changes (especially considering point number 3 that I raised). Will be glad to hear your insights on this and/or any suggestion for fixing the issue. Thanks!

@jknack jknack added the bug label May 27, 2018
@jknack jknack added this to the 4.0.7 milestone May 27, 2018
@jknack
Copy link
Owner

jknack commented May 27, 2018

Fixed with #588 and #620:

handlebars.setPreEvaluatePartialBlocks(false);

@jknack jknack closed this as completed in 4773a5b May 27, 2018
@dudabone
Copy link
Author

dudabone commented Aug 7, 2018

Hi @jknack, thanks for the fix. Sorry for bugging on this with a such long comments :) but either I didn't get it right or that the fix does not really cover the scenario that I have described. You can see that also in the test that you added the expected result is not the same as I described - the "inherit1" partial is not rendering the "inline partial defined by inherit1, called from base" content, which was defined in the partial block (if needed I can commit a change to the test that better describes the expected result, I believe it will fail though).

I am assuming that this is because the fix requires to call {{>@partial-block}} in order to render the inner content of an inherited partial block, but this does not solve my problem since it requires to go over all templates that are being inherited and add {{>@partial-block}} to them. This is not so applicable since not all inheriting templates actually define a partial block when calling the base template, so you get a "[template] does not provide a @partial-block" exception.

To my understanding the functionality that I am describing (inline partials remaining in the partial block context) is meant to be supported for without the need to call {{>@partial-block}}, as described in the second example of inline partials here ("Each inline partial is available to the current block and all children, including execution of other partials...").

Can you please shed some light on this? Am I missing something? This will be really helpful as my application heavily reuses templates and to workaround this issue I need do define empty inline partials in order to "reset" the ones that were defined by a sibling template.

Thanks!

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

No branches or pull requests

2 participants