What happened to didInsertElement in the component API documentation?

What happened to the component lifecycle hooks in the API documentation? It is clearly referenced in the v2.4 guide, but not in the API docs.

I was confused about the guide showing a this.super() call on a didInsertElement example, and went to go look up the API docs, but was surprised to find it missing. Not even under deprecated.

And since when is it required to call this._super() in didInsertElement?

didInsertElement only appears under Ember - 4.6 - Ember API Documentation

which is a mixin that Ember.Component uses.

1 Like

What I’ve learned is that when overriding/extending methods, you should call this._super(...arguments) as best practice.

See ComponentBestPractices

1 Like

@Guarav: You’re right - I see it in the code, however it seems that the documentation does not reflect this in the inherited properties.

@rmmpaderes: After a little digging, it appears that the base class defines didInsertElement as follows:

didInsertElement: K,

where K is simply the identity function (return this), so calling this._super() in didInsertElement seems superfluous, as there is no default behavior upon insertion of the element. The only justification I can imagine for continuing to do so is in the case that a default behaviour is introduced in the future.

Thanks!

Yes that’s the reason why it’s best practice to use super, in case that a default behavior is introduced in the future (which I don’t think it will, but you never know :wink:).

Another example is if you have a mixin that implements didInsertElement() inside the component. So in order to execute the didInsertElement() of the component before running the one in the mixin, you use super. If however, you’re absolutely sure that it will never happen then feel free to not omit. But again, with the first reason above, it should be sufficient to convince you to use it as best practice.

Thanks to Gaurav’s PR here: [DOC] Restore missing component events like didInsertElement by Gaurav0 · Pull Request #13237 · emberjs/ember.js · GitHub this is now in the API docs. In the future, if you notice things like this, opening an issue is much appreciated! :wink:

1 Like