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

HeadingView not destroyed when parent View is destroyed #516

Closed
oliverfoster opened this issue Apr 10, 2024 · 1 comment · Fixed by #517 or #527
Closed

HeadingView not destroyed when parent View is destroyed #516

oliverfoster opened this issue Apr 10, 2024 · 1 comment · Fixed by #517 or #527
Assignees
Labels

Comments

@oliverfoster
Copy link
Member

oliverfoster commented Apr 10, 2024

Subject of the issue

HeadingView instances are created when required:

initialize() {
this.listenTo(Adapt, 'view:render', this.onViewRender);
}
onViewRender(view) {
const $headingSeats = view.$('.js-heading');
$headingSeats.each((index, el) => new HeadingView({ el, model: view.model }));
}

When a contentobject is destroyed it removes its descendant views but not the HeadingView as it has no handle to them:

remove() {
const type = this.constructor.type;
this.preRemove();
Adapt.trigger(`${type}View:remove contentObjectView:remove view:remove`, this);
this._isRemoved = true;
wait.for(end => {
if (this.isJSX) {
ReactDOM.unmountComponentAtNode(this.el);
}
this.$el.off('onscreen.adaptView');
this.findDescendantViews().reverse().forEach(view => {
view.remove();
});

If a floating HeadingView model is _isComplete updated, it will rerender its ariaLabel:

this.listenTo(this.model, 'change:_isComplete', this.updateAria);

This is a memory leak.

@oliverfoster
Copy link
Member Author

I missed the contentObjectView in the fix when adding preRemove and remove events.

remove() {
const type = this.constructor.type;
this.preRemove();
Adapt.trigger(`${type}View:remove contentObjectView:remove view:remove`, this);
this._isRemoved = true;
wait.for(end => {
if (this.isJSX) {
ReactDOM.unmountComponentAtNode(this.el);
}
this.$el.off('onscreen.adaptView');
this.findDescendantViews().reverse().forEach(view => {
view.remove();
});
this.setChildViews(null);
super.remove();
_.defer(() => {
Adapt.trigger(`${type}View:postRemove contentObjectView:postRemove view:postRemove`, this);
this.trigger('postRemove');
});
end();
});
return this;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment