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

Fix event leak on reuse of touchbar item #12527

Merged
merged 2 commits into from Apr 15, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/browser/api/touch-bar.js
Expand Up @@ -118,6 +118,9 @@ class TouchBar extends EventEmitter {
window.removeListener('closed', removeListeners)
window._touchBar = null
delete this.windowListeners[id]
for (const item of this.ordereredItems) {
Copy link
Member

Choose a reason for hiding this comment

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

'ordereredItems'? not new to this PR, but... 🙄 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

items is a map of id --> item
orderedItems is an array giving you the left->right order of those items containing references to the objects in the items map

Copy link
Member

Choose a reason for hiding this comment

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

Right, I get it. Just amused by the spelling ordereredItems 🥈

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, wow, ok. That's a typo I never noticed 😆

item.removeListener('change', this.changeListener)
Copy link
Member

Choose a reason for hiding this comment

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

I think this is undoing the item.on('change', this.changeListener) in registerItem(), but the next line there is to also register each of item.child.ordereredItems iff item.child is a TouchBar. Do we need to undo that here too?

If we don't also need that, then I'm 👍 on this PR

Copy link
Member

Choose a reason for hiding this comment

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

edit: and walking recursively down all TouchBar subtrees

Copy link
Member

Choose a reason for hiding this comment

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

edit 2: do we also need to remove the escapeItem changeListener too?

Copy link
Member Author

Choose a reason for hiding this comment

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

I now clean up recursively and deal with the escapeItem listener

}
}
window.once('closed', removeListeners)
this.windowListeners[id] = removeListeners
Expand Down