Hotwire Discussion

Event listener on body is not being removed

Hi, so i have this event listener

  connect() {
    console.log("connecting it")
    if(this.attachToBodyValue) {
      document.addEventListener("scroll", this.bodyScrollListener.bind(this));

  disconnect() {
    document.removeEventListener('scroll', this.bodyScrollListener.bind(this));

The thing is, when i navigate away from the page, the function is still there, and if i navigate to the bottom it will go to the infinite-scroll URL. this is the result of `getEventListeners(document) before leaving the page.

and after leaving the page, the same call to getEventListeners(document) will get the same result back, the listener isnt being removed for some reason.

Any ideas are greatly appreciated, thanks

turns out i was missing javascript 101.

i had to bind only in initialize