You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there is no way for top-level expressions to be correctly bound to a parent container when written in a plain template. Components do not need a warning, neither do any templates provided a parentNode or nodeList to render inside when passed to can-view-live/live.html().
For examples, these templates should warn:
{{#if username}}<p>Hello {{username}}</p>{{/if}}
<div>Hello CanJs</div><!-- this is still top-level -->
{{#if info}}<p>Info</p>{{/if}}
I'm unsure what the best warning message would be. Maybe Top-level template expressions cannot be bound in a performant manner, please place "${given expression}" within an element. Please see ${link to better explanation because there definitely should be one}.
There are technical limitations to how nodes are transferred from a DocumentFragment to the main document which makes this an unsolvable bug for now /cc @justinbmeyer.
The text was updated successfully, but these errors were encountered:
After discussion with Justin, I learned that it's not a performance problem and it is about the inability to tear down properly without an element to hitch to.
If you create a Stache with a top level HTML element, it can tear down bindings associated with itself because the root element can listen for a mutation that removes it. Without this as the top level, a Stache that's rendered and placed into the document outside of other can-view-callbacks rendered DOM trees will not be able to tear down its bindings when the text nodes at the top level are removed, and a memory leak could result. This isn't a problem if you don't ever intend to remove that stache or its ancestor from the page, but this is not the only use case.
So we need some resources to help people make staches that can tear down if removed, if they're not just a top level element (i.e. they contain text nodes or magic tags not contained in an element). This should take the form of docs with a recipe at the very minimum (and we can point to the docs in the warning message), a helper function that abstracts the top level nodelist and teardown function that would need to be created is better.
Currently, there is no way for top-level expressions to be correctly bound to a parent container when written in a plain template. Components do not need a warning, neither do any templates provided a parentNode or nodeList to render inside when passed to can-view-live/live.html().
For examples, these templates should warn:
I'm unsure what the best warning message would be. Maybe
Top-level template expressions cannot be bound in a performant manner, please place "${given expression}" within an element. Please see ${link to better explanation because there definitely should be one}
.There are technical limitations to how nodes are transferred from a DocumentFragment to the main document which makes this an unsolvable bug for now /cc @justinbmeyer.
The text was updated successfully, but these errors were encountered: