ember.js icon indicating copy to clipboard operation
ember.js copied to clipboard

[Bug] Error when @computed property depends on a key that is not defined on a hash created using {{hash}} helper

Open nicolastrres opened this issue 5 years ago • 3 comments

🐞 Describe the Bug

An error is raised when a @computed property depends on a key of a hash created using the {{hash}} helper and the key is not defined in the hash.

Example:

{{!-- app/components/example-component/template.hbs --}}
<h1>{{this.label}}</h1>
// app/components/example-component/component/js
export default class ExampleComponentComponent extends Component {
  // label computed property depends on the `label` key of the `item` object
  @computed('item.label')
  get label() {
    return this.item.label ?? 'Empty label';
  }
}
{{!-- app/templates/application.hbs --}}
{{!-- the following hash does not contain a `label` key --}}
<ExampleComponent @item={{hash someProperty="other"}} />

🔬 Minimal Reproduction

Minimal reproduction project

😕 Actual Behavior

The following error is being raised:

Uncaught TypeError: Cannot destructure property 'tag' of 'ref' as it is undefined.
    at valueForRef (reference.js:144)
    at runtime.js:6931
    at track (validator.js:820)
    at tagForKey (runtime.js:6931)
    at runtime.js:7006
    at tagForProperty (index.js:516)
    at getChainTags (index.js:907)
    at getChainTagsForKeys (index.js:824)
    at ComputedProperty.get (index.js:1939)
    at ExampleComponentComponent.getter [as label] (index.js:1024)

🤔 Expected Behavior

No error should be shown and the computed property should work properly.

🌍 Environment

  • Ember: 3.28.0-beta.1.beta
  • Node.js/npm: v14.0
  • OS: Mac OSX
  • Browser: Safari andChrome

➕ Additional Context

This was working properly a couple of days ago but started breaking in the latest beta version.

nicolastrres avatar May 26 '21 23:05 nicolastrres

This line needs to have an in check in it: https://github.com/glimmerjs/glimmer-vm/blob/master/packages/@glimmer/runtime/lib/helpers/hash.ts#L10

Ideally we should add some tests to Glimmer VM to test the custom tag for functionality, but I'm not sure if that would actually test it well enough because most of the usage/implementation is in Ember 😕 we can definitely add an integration test on the Ember side though.

pzuraq avatar May 27 '21 01:05 pzuraq

it looks like https://github.com/rust-lang/crates.io/pull/3656 is still failing, despite the bugfix 😢

Turbo87 avatar Jun 06 '21 07:06 Turbo87

@Turbo87 this fix was unrelated to the issue in Crates, that will be fixed by this PR: https://github.com/emberjs/ember.js/pull/19584

We are currently planning on landing that fix on Beta, and reverting the other fixes on release in order to reduce risk, it's clear that the changes to hash are introducing further complications and we want more time to get them right.

pzuraq avatar Jun 06 '21 23:06 pzuraq