-
Notifications
You must be signed in to change notification settings - Fork 59
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
Attached and detached events not firing when expected when conditionally rendering JSX children. #115
Comments
You're right that these lifecycle events/functions should be fired in this case. I can see from looking at the code why |
Thanks Maira! On Wed, May 25, 2016 at 10:16 AM, Maira Bello [email protected]
Evan Thibodeau UI Software Engineer |
@ethib137, I investigated a bit and it seems like the lifecycle functions are actually being called at the right time. There are two things that may be happening in your case:
|
@mairatma so am I understanding it correctly in saying that the Cause I am testing use case 2 and I am not seeing |
Also, say I have two components, C1 and C2. <C1>
<C2 />
</C1> If I dispose C1, will C2 also be disposed? |
No, both the Can you show me the code you're testing this with so I can try to investigate if it's some kind of bug? And yes, when a parent component is disposed, its child components are disposed as well (or at least they should be). |
|
Actually I just cleared out and re-installed latest npm modules and it seems to work now. Let me test in Loop specifically and get back to you. |
okay I was able to reproduce outside of loop using. Issue seems to be specifically when passing through Components: import Component from 'metal-jsx';
class ParentComponent extends Component {
onClick() {
this.active = !this.active;
}
render() {
return (
<div>
<button data-onclick={this.onClick.bind(this)}>hide child</button>
{this.active &&
this.config.children
}
</div>
);
};
}
ParentComponent.STATE = {
active: {
value: true
}
}
export class ChildComponentTwo extends Component {
attached() {
console.log("child-attached");
}
detached() {
console.log("child-detached");
}
render() {
return (
<div>
child
</div>
);
};
}
export default ParentComponent; render via <ParentComponent>
<ChildComponentTwo />
</ParentComponent> |
Oh I see now, that makes sense, thanks a lot for the detailed example! I'll work on fixing this. |
This should be fixed now, just update the dependencies :) Let me know if there's any other case where these lifecycle events aren't being fired. I believe I've covered everything, and I've added test cases to make sure these problems don't come back. |
Thanks @mairatma! |
I have written a tab component that works by only rendering one of it's child components at a given time (https://github.com/liferay/liferay-plugins-ee/blob/ee-6.2.x/portlets/loop-portlet/docroot/js/src/components-metal/Tabs.js#L66).
I would expect that each time I switch a tab, the previous child component would be "detached", and the new child component would be "attached".
What is actually happening is that the "attached" event is only running the first time the child component is rendered. After I have viewed a child component once, even if I switch to a different tab and come back, the "attached" event will not fire a second time. Also, the "detached" event is never fired.
Please let me know if I am thinking about the lifecycle correctly or if you need any clarifications.
Thanks.
The text was updated successfully, but these errors were encountered: