[BUGFIX lts] Ensure destroy
methods on CoreObject
are invoked.
#19106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When an instance of
CoreObject
is destroyed with@ember/destroyable
(or the polyfill when using Ember 3.20+), the instances owndestroy
method is never called. In general "this is fine" because the majority of consumers are usingwillDestroy
for their custom object teardown needs. Unfortunately, this isn't quite good enough and any consumers that are directly relying on extending fromCoreObject
and having a customdestroy
method called will no longer function.The prime example of this is the
Owner
instance itself. Currently, runningdestroy(owner)
does not actually destroy any instantiated objects in the container. This is becauseContainerProxyMixin
implementsdestroy
in order to callthis.__container__.destroy()
which is where the actual cleanup happens. That whole system should be refactored to leveraging@ember/destroyable
system directly, but in the meantime this case (and any others where folks have implemented a destroy method in Mixins or other subclasses of Ember.CoreObject) should absolutely be fixed.This fix ensures that any
destroy(someInstance)
calls on aCoreObject
directly invoke thedestroy
method on the instance in the same manner as Ember < 3.20 (.destroy()
is called eagerly, beforewillDestroy
).