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

Popup does not clean up event listeners if closeOnClick: true #11535

Closed
Pessimistress opened this issue Feb 19, 2022 · 1 comment · Fixed by #11540
Closed

Popup does not clean up event listeners if closeOnClick: true #11535

Pessimistress opened this issue Feb 19, 2022 · 1 comment · Fixed by #11540

Comments

@Pessimistress
Copy link

mapbox-gl-js version: 2.7.0

browser: any

Steps to Trigger Behavior

  1. Create popup with closeOnClick: true
  2. Add listener to the popup's close event
  3. After the popup is closed, the close event continue to fire upon any click on the map

Link to Demonstration

https://codepen.io/Pessimistress/pen/qBPmbrV

  1. Click on "open popup"
  2. Click anywhere on the map
  3. Repeat 1 & 2 a few times, observe console logs

Expected Behavior

The close callback should be called once for each popup

Actual Behavior

All close callbacks ever registered continue to be called when the map is clicked.

I believe this was introduced by 9c1e1a0, as a preclick listener is added to the map:

map.on('preclick', this._onClose);

But on popup.remove it attempts to remove a click listener:

map.off('click', this._onClose);

This bug cannot be reproduced on versions <2.5.0, when this commit was included.

@ryanhamley
Copy link
Contributor

Thanks for the report @Pessimistress I submitted #11540 to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants