taye / interact.js

JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)
http://interactjs.io/
MIT License
12.38k stars 785 forks source link

Interact lib does not remove global listeners on unset #598

Closed artaommahe closed 6 years ago

artaommahe commented 6 years ago

After calling on single interact instance

      .draggable(false)
      .resizable(false)
      .unset()

there are still document listeners like pointermove that were not cleaned up, they work on every page despite interact usage. It's huge slowdown for SPA and slow PC/IE11. (mouse move on empty area with 4x slowdown on dev pc) image

After some debugging i found that i need to call manually

interact(document)
  .unset();

But this will not work due to error on this line (wrong on prefix) https://github.com/taye/interact.js/blob/master/src/utils/events.js#L88 while when we add listeners there is no on prefix https://github.com/taye/interact.js/blob/master/src/utils/events.js#L53 After removing this prefix everything works fine. So there is 2 problems

artaommahe commented 6 years ago

Looks like removing listeners from document breaks interact and he cant add them one more time after unset.

taye commented 6 years ago

Try updating to v1.4.0-alpha and using interact.removeDocument(document). Calling interact(anyTarget) again adds the document back or you can do interact.addDocument(document).

artaommahe commented 6 years ago

@taye it works, thx

luanraithz commented 5 years ago

@taye Is there anything in the doc that say something about this whole process? I have lost some hours while trying to solve a bug with react-router-dom and interactjs, which was caused by many event listeners. The problem was that on second time I tried to move a draggable item ( after leaving the screen and comming back ) the item was moved twice the distance. If there is no section about this in the doc, it would be nice if someone write about it ( I may do it my self if you ask).