-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
check if component is initialized before removing #2713
Conversation
src/core/a-entity.js
Outdated
if (!component) { return; } | ||
|
||
// Wait for component to initialize. | ||
if (!component.initialized) { |
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.
What about doing just?
if (!component || !component.initialized) { return; }
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.
Then the removeComponent
call will never go through. A warning might be simpler though.
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.
Maybe it's best to try to make sure that component gets cleaned up. Might cause leaks or unexpected behavior if we let it be orphaned in the case entities are being attached/detached before the component initializes?
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.
Asynchrony might bite you. What happens if you do:
myMethod () {
this.setAttribute('my-component', { });
this.removeAttribute('my-component');
this.setAttribute('my-component', {});
}
I believe the component will be removed if the component was not initialized in the first call
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.
Initialization is already synchronous. After you do setAttribute
, the component will be initialized immediately and thus the code I added will never run.
This PR is only in the case when you do appendChild/removeChild because that's inherently asynchronous, no way around it.
@ngokevin: sorry, I think Waffle automatically added that on my behalf |
Description:
Was running into errors in unit test if you detached an entity while one of its components was still initializing. Its data would be
null
because it had not yet built data, and.removeComponent
would be called. Geometry would then be callingsystem.unuseGeometry(data)
wheredata
was null, causing an error.Changes proposed:
componentinitialized
inremoveComponent
if not initialized.