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
{{ message }}
Repository navigation
"Assertion Failed: You can only pass a path to mut" in template only glimmer component #17202
Hmm, I don't fully understand what the goal here is. Using showSomething here (unless it is passed as an argument) is ultimately going to try to do a this.showSomething lookup, but with the template only glimmer component feature flag enabled there is no thisat all which is most likely causing the error you are seeing. What do you expect to be backing the mutable showSomething binding?
As a general rule any template only glimmer component's path expressions should either be a block param in scope or a named argument, anything else (IMHO) should error at compile time.
@GavinJoyce - In this scenario what would you have expected to happen?
As a general rule any template only glimmer component's path expressions should either be a block param in scope or a named argument, anything else (IMHO) should error at compile time.
I'm not 100% sure how easy or hard this would be to implement at the moment, since its unknown at template compilation if a given template is going to be used as a template only component (and frankly its possible that templates are shared so it may not be possible...).
The no-implicit-this template linting rule would be somewhat helpful here, but only in making it clearer that this is being used when it shouldn't be (and also should make the error message clearer). Docs for that here
{{#let (data-bag) as |data|}}{{#ifdata.showSomething}}
[Here's your something]
<buttononclick={{action (mutdata.showSomething) false}}>Hide</button>
{{else}}
<buttononclick={{action (mutdata.showSomething) true}}>Show</button>
{{/if}}{{/let}}
Where data-bag returns a stable object for stashing state.
However, we should really think hard about why we want to keep this a template only component. It does have its own local UI state that it is tracking...
What specifically does this mean when there is no backing data structure?
My understanding of templates, which now appears to be wrong, was that they have a local context and that the mut helper could be used to mutate properties on that context. I can see why this mightn't be the case with template only components though.
I'm keen to replace our most frequently rendered components with template only components, mainly for performance reasons. Not being able to mutate local properties with mut and friends would likely be a barrier to removing all JS from some of these components.
One possible solution is what I submitted in a PR to your demo...
That's an interesting approach, thanks!. It seems like it gives us a way forward in our app should we feel that the benefits outweigh the possible downsides
@GavinJoyce - Depending on Ember version, I'd suggest something like sparkles-component as a possible path forward. It effectively removes any instantiation cost that Ember.Component has (it really is a super tiny base class), and was created to align with future @glimmer/component APIs.
This thread is going to be very useful to a lot of people as template-only components become more prevalent. I had the same misunderstanding and this is the clearest explanation I’ve seen.
Reacted by David Newell, Gaurav Munjal, Jonny Green, Ed Phillips, Sebastián Duque, Scott Newcomer, Makala Noble and Karl He
Activity
bekzod commentedon Nov 12, 2018
great usecase for
lethelper :Prwjblue commentedon Nov 12, 2018
Hmm, I don't fully understand what the goal here is. Using
showSomethinghere (unless it is passed as an argument) is ultimately going to try to do athis.showSomethinglookup, but with the template only glimmer component feature flag enabled there is nothisat all which is most likely causing the error you are seeing. What do you expect to be backing the mutableshowSomethingbinding?As a general rule any template only glimmer component's path expressions should either be a block param in scope or a named argument, anything else (IMHO) should error at compile time.
@GavinJoyce - In this scenario what would you have expected to happen?
rwjblue commentedon Nov 12, 2018
I'm not 100% sure how easy or hard this would be to implement at the moment, since its unknown at template compilation if a given template is going to be used as a template only component (and frankly its possible that templates are shared so it may not be possible...).
The
no-implicit-thistemplate linting rule would be somewhat helpful here, but only in making it clearer thatthisis being used when it shouldn't be (and also should make the error message clearer). Docs for that hereGavinJoyce commentedon Nov 12, 2018
This seems to fail in the same way:
GavinJoyce commentedon Nov 12, 2018
I'm hoping to be able to be able to implement a toggle on a local property in a template only component without needing to define a JS class.
rwjblue commentedon Nov 12, 2018
Gotcha!
What specifically does this mean when there is no backing data structure?
rwjblue commentedon Nov 12, 2018
FWIW, the super bad error message is definitely a bug either way. There is even a TODO in the code explaining what is happening:
ember.js/packages/@ember/-internals/glimmer/lib/helpers/mut.ts
Lines 96 to 108 in abdce14
rwjblue commentedon Nov 12, 2018
One possible solution is what I submitted in a PR to your demo repo GavinJoyce/template-only-mut-bug#1:
Where
data-bagreturns a stable object for stashing state.However, we should really think hard about why we want to keep this a template only component. It does have its own local UI state that it is tracking...
GavinJoyce commentedon Nov 12, 2018
My understanding of templates, which now appears to be wrong, was that they have a local context and that the
muthelper could be used to mutate properties on that context. I can see why this mightn't be the case with template only components though.I'm keen to replace our most frequently rendered components with template only components, mainly for performance reasons. Not being able to mutate local properties with
mutand friends would likely be a barrier to removing all JS from some of these components.That's an interesting approach, thanks!. It seems like it gives us a way forward in our app should we feel that the benefits outweigh the possible downsides
rwjblue commentedon Nov 12, 2018
@GavinJoyce - Depending on Ember version, I'd suggest something like sparkles-component as a possible path forward. It effectively removes any instantiation cost that
Ember.Componenthas (it really is a super tiny base class), and was created to align with future@glimmer/componentAPIs.GavinJoyce commentedon Nov 12, 2018
@rwjblue I'll try that, thanks.
Let's close this issue?
jgwhite commentedon Nov 13, 2018
This thread is going to be very useful to a lot of people as template-only components become more prevalent. I had the same misunderstanding and this is the clearest explanation I’ve seen.