-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Reuse RenderContext
after executing partial
#624
Comments
Yes because partial has its own context data. I'm curious about your use case for reusing the |
Hi @sunng87 , thanks for your update My case is that I have an // _partial.hbs
...
{{#assign "foo"}}
bar
{{/assign}}
... // parents.hbs
...
{{> _partail}}
...
{{foo}} <---- expected to show "bar" After spending time tracing source, it seems to me the closest solution is to add it into |
I think it's not possible also it's not recommended to have data modification in templates, which has poor debug experience. I will suggest you to prepare the data ahead of rendering and feed to the template directly. |
Regardless of the original usecase given in this issue, that clone is a major performance issue. Unfortunately the relevant lifetimes are very deeply engrained into the system, so changing this I threw together a proof of concept refactor over here: https://github.com/cmrschwarz/handlebars-rust/tree/avoid_context_clone. This basically eliminates the 'rc and 'reg lifetimes entirely. For one my personal usecases, where I have to emit quite a large amount of HTML containing quite a few nested partials, As all the indenting changes will probably require a major version bump anyways, |
This sounds promising to me. Have you tried benchmark with you new implementation? The current partial has a step of context clone, which I believe is the root cause of slowness. But although I'm OK with a breaking change and major release, I wonder if it's possible to keep |
For now, because of the following line of code, handlebars doens't share
RenderContext
when rendering partial.https://github.com/sunng87/handlebars-rust/blob/9d7d5556287e31e4148841a56e0981b64a679fb6/src/partial.rs#L61C9-L61C39
Is it possible to fix it and have a universal
RenderContext
whenrendering
?The text was updated successfully, but these errors were encountered: