Skip to content
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

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

Closed
nicolastrres opened this issue May 26, 2021 · 3 comments · Fixed by glimmerjs/glimmer-vm#1318 or #19565

Comments

@nicolastrres
Copy link

🐞 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 nicolastrres changed the title [Bug] Error raised when @computed property depends on a key that is not defined on a hash created using {{hash}} helper [Bug] Error when @computed property depends on a key that is not defined on a hash created using {{hash}} helper May 26, 2021
@pzuraq
Copy link
Contributor

pzuraq commented May 27, 2021

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.

@Turbo87
Copy link
Member

Turbo87 commented Jun 6, 2021

it looks like rust-lang/crates.io#3656 is still failing, despite the bugfix 😢

@pzuraq
Copy link
Contributor

pzuraq commented Jun 6, 2021

@Turbo87 this fix was unrelated to the issue in Crates, that will be fixed by this PR: #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants