ember.js: Rendering
In ember 3.3.0 following template breaks application:
{{#each buttons as |button|}}
<button>{{button}}</button>
{{/each}}
buttons is a simple array. In console I can see Uncaught Error: unreachable. This error does not happen with other tags (i.e. works fine) and does not happen on ember 3.2.2
Repository with demonstration: https://github.com/GendelfLugansk/ember-rendering-bug
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 8
- Comments: 44 (25 by maintainers)
Commits related to this issue
- Do not used reserved keywords in each loops (https://github.com/emberjs/ember.js/issues/16826) — committed to csvalpha/amber-ui by Matthijsy 4 years ago
- Ember 3.6 (#107) * v3.2.0...v3.4.4 # Conflicts: # .template-lintrc.js # .travis.yml # README.md * Run codemods * Add some missing fa-icons and wrong translator * Do not used reserved k... — committed to csvalpha/amber-ui by Matthijsy 4 years ago
Yes, it is a breaking change and we are working on the fix.
The current behavior matches what the RFC stated (essentially that a block param named
button+<button></button>in the blocks template, would assume that the block param was a yielded closure component and attempt to render it as such), but based on feedback (here and in other issues) we determined that the result is definitely something we consider a breaking change.The current plan (after discussing with the core team on 2018-07-20) is:
until: '4.0.0')This change should not have happened during 3.3, and we will try to figure out why it did (and fix it). However, we do intend for it to land as part of 3.4 (along with support for linting in applications as a general guide).
Ya, I mentioned above that we consider this a bug and totally want to make the ergonomics much better (e.g. issue a warning that has a helpful message instead of error).
@nightire as I can tell, we can use html tag name in
aspart if that html tag is not used inside block. I also think it affects not justeachbut any block helper that yields something, including our own components.Changing to:
Should resolve the issue (assuming that my guess RE: angle bracket invocation feature is correct).
@pzuraq yes, I can reproduce this error using 3.8.0
Probably, but its still a good idea to refactor away from the patterns that are currently breaking.
The ember-template-lint rule
no-shadowed-elementsis a great way to enforce this.Just another information: this issue tricks me a lot, the key is: don’t use html tag name as the
aspart ofany helper that yields something.eachI’m not sure if it will be a breaking change, but I hope not.
FYI just spent a couple hours on debugging til I finally googled and found this issue (was using option and the yielded name) so its still out there on 3.15.
What was weird was that {{log option}} reported the correct value inside the loop, so never occurred to me the name of the variable could be the problem
@BobrImperator I’m not sure that problem is something that is possible to catch ahead of time, and it should have always been a failure because local variables have always taken precedence over globals. The reason we can’t catch it ahead of time is similar to why you can’t lint against something like this in JS:
While it’s reasonable to assume that this is a shadowing mistake on the developer’s part, because of JS’s dynamic nature, we can’t know for sure that
foois not a function when being passed intobar. If we were using a typed language instead, then we may be able to, but unfortunately I don’t think we can currently.@rwjblue No worries! If the linter picks it up then that is good. It is only a result of bad coding anyway.
@Caltor https://github.com/emberjs/ember.js/issues/16826#issuecomment-405654150 there is workaround for this case, and workaround pretty clear and it’s following official linting rules https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-shadowed-elements.md
👍 thanks for that (and sorry for the issue)
Confirm, yielding any block param that will be used as an angle bracket invocation will result in this issue.
See the following issues for some more background information: