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

Add some information about uninitialized class properties #493

Closed
wants to merge 2 commits into from

Conversation

mfeckie
Copy link
Contributor

@mfeckie mfeckie commented Dec 24, 2018

Got burned by unintialized class properties, which relates to babel/babel#9141

}
```

When invoked via a template `{{user-profile username='example123'}}`, you would expect that `username` would have the value of `example123`, however prior to the native class feature released in Ember `3.6`, this will result in `username` being undefined.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider whether it's preferable to just include ember-native-class-polyfill as either a dependency or something we check for in this addon's included() hook. Looks like the polyfill supports at least Ember 3.4 (pzuraq/ember-native-class-polyfill#11) which satisfies our framework version support policy.

The root cause of the problem this documentation is trying to help users avoid, is that babel 7 auto-initializes uninitialized properties to void 0 (possibly for perf reasons, so runtimes see instances as having a consistent shape), which interferes with the way we expect Ember.Component (and Glimmer.Component) to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing the field as void 0 / undefined has the side-effect of being good for perf, but Babel primarily does this to be spec-compliant.

babel/babel#9105 and babel/babel#9141 go into detail about this.

@igbopie
Copy link

igbopie commented Dec 24, 2018

The polyfill might be the solution for me as I ran into issues with ember upgrade.

Copy link
Contributor

@buschtoens buschtoens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

babel/babel#9105 is not touched upon explicitly here. When a subclass narrows down the type of a property of its superclass, the property is overridden as undefined.

@chriskrycho
Copy link
Member

@mfeckie I'm going to rebase this on Monday so I can incorporate these notes into my docs PR (#599) and get it landed as I update the docs. Thank you again!

@chriskrycho
Copy link
Member

GitHub is confused; this landed via 28059eb. Thanks again @mfeckie!

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

Successfully merging this pull request may close these issues.

None yet

5 participants