-
Notifications
You must be signed in to change notification settings - Fork 99
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
Conversation
} | ||
``` | ||
|
||
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
The polyfill might be the solution for me as I ran into issues with ember upgrade. |
There was a problem hiding this 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
.
a0f7ccd
to
6ed57f9
Compare
Got burned by unintialized class properties, which relates to babel/babel#9141