Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(whatInput): cleanup previously added event listeners #2127

Merged
merged 7 commits into from
Nov 26, 2019

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Nov 25, 2019

Fixes #2109

Counting on target[whatInputInitialized] the number of Providers requesting to setup the custom-target whatInput.

To cleanup, in Provider componentWillUnmount we will attempt to remove listeners. If there are still Providers running (target[whatInputInitialized] > 1) then we will decrement that value. If it's the last one, then we perform cleanup.

Extra:

  • in whatInput.ts I changed useCapture with capture (line 92). According to the docs that is the correct property if we pass the information inside the options object params.

To Do:

  • add test to check cleanup is performed.
Microsoft Reviewers: Open in CodeFlow

if (eventTarget.PointerEvent) {
eventTarget.removeEventListener('pointerdown', setInput)
// @ts-ignore
} else if (window.MSPointerEvent) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

still thinking why here there is window and not eventTarget.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am replacing this. @jurokapsiar @layershifter any comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is basically a platform check - saying "does this browser have MSPointerEvent?"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will revert it then, but shouldn't the check above mean similarly? eventTarget.PointerEvent

Copy link
Member

@miroslavstastny miroslavstastny left a comment

Choose a reason for hiding this comment

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

Approved, it would be great if @jurokapsiar could check it as well as he originally added multi-window support

</Provider>,
)

expect(addEventListener).toHaveBeenCalledTimes(5)
Copy link
Member

Choose a reason for hiding this comment

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

black magic

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok ok will add a comment why :))))

@@ -87,14 +89,14 @@ const addListeners = (eventTarget: Window) => {
// `pointermove`, `MSPointerMove`, `mousemove` and mouse wheel event binding
// can only demonstrate potential, but not actual, interaction
// and are treated separately
const options = supportsPassive ? { passive: true, useCapture: true } : true
const options = supportsPassive ? { passive: true, capture: true } : true
Copy link
Member

Choose a reason for hiding this comment

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

👍

@silviuaavram silviuaavram merged commit e7722e5 into master Nov 26, 2019
@silviuaavram silviuaavram deleted the fix/whatinput-memory-leak branch November 26, 2019 08:23
miroslavstastny pushed a commit that referenced this pull request Nov 26, 2019
* cleanup event listeners

* type check improvement

* replace window occurance

* add tests

* changelog

* improve tests

* revert change of window
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory: Window object leaks in what-input.ts
3 participants