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

[BUGFIX lts] Ensure destroy methods on CoreObject are invoked. #19106

Merged
merged 1 commit into from
Aug 25, 2020

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Aug 25, 2020

When an instance of CoreObject is destroyed with @ember/destroyable (or the polyfill when using Ember 3.20+), the instances own destroy method is never called. In general "this is fine" because the majority of consumers are using willDestroy for their custom object teardown needs. Unfortunately, this isn't quite good enough and any consumers that are directly relying on extending from CoreObject and having a custom destroy method called will no longer function.

The prime example of this is the Owner instance itself. Currently, running destroy(owner) does not actually destroy any instantiated objects in the container. This is because ContainerProxyMixin implements destroy in order to call this.__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 a CoreObject directly invoke the destroy method on the instance in the same manner as Ember < 3.20 (.destroy() is called eagerly, before willDestroy).

@rwjblue rwjblue added the Bug label Aug 25, 2020
@rwjblue rwjblue requested a review from pzuraq August 25, 2020 16:49
@rwjblue
Copy link
Member Author

rwjblue commented Aug 25, 2020

That whole system should be refactored to leveraging @ember/destroyable system directly

FWIW, I am working on another PR (that won't be [BUGFIX lts]) to do this.

@rwjblue rwjblue force-pushed the core-object-with-destroy branch 4 times, most recently from 12fe448 to 5b1c358 Compare August 25, 2020 19:27
@@ -256,6 +266,7 @@ class CoreObject {
});
}

registerDestructor(self, ensureDestroyCalled, true);
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this is specifically an eager destructor to match the previous semantics. The .destroy method would always have gotten called before the downstream objects are marked as isDestroying and before the instances own .willDestroy is called.

When an instance of `CoreObject` is destroyed with `@ember/destroyable`
(or the polyfill when using Ember 3.20+), the instances own `destroy`
method is never called. In _general_ "this is fine" because the majority
of consumers are using `willDestroy` for their custom object teardown
needs. Unfortunately, this isn't _quite_ good enough and any consumers
that are directly relying on extending from `CoreObject` and having a
custom `destroy` method called will no longer function.

The prime example of this is the `Owner` instance itself. Currently,
running `destroy(owner)` **does not** actually destroy any instantiated
objects in the container. This is because `ContainerProxyMixin`
implements `destroy` in order to call `this.__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 a
`CoreObject` directly invoke the `destroy` method on the instance in the
same manner as Ember < 3.20 (`.destroy()` is called eagerly, before
`willDestroy`).
@rwjblue rwjblue merged commit 5187b7f into master Aug 25, 2020
@rwjblue rwjblue deleted the core-object-with-destroy branch August 25, 2020 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants