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

deregister marker mouseup and touchend when removing marker #7442

Merged
merged 1 commit into from
Oct 19, 2018
Merged

deregister marker mouseup and touchend when removing marker #7442

merged 1 commit into from
Oct 19, 2018

Conversation

vbud
Copy link
Contributor

@vbud vbud commented Oct 18, 2018

We have run into scenarios where we remove a draggable marker before mouseup is ever fired and, because mouseup/touchend never fired once, _onUp is called but the marker has already been torn down, leading to errors.

Ensuring these listeners are deregistered when tearing down the marker will ensure that doesn't happen.

I didn't see any tests in the marker unit test file that ensure that listeners are being deregistered, so I did not add any tests with this. Let me know if I missed anything. Tests added.

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! This test would have caught the error you're seeing. Would you mind adding it to the marker.test.js file

test('Marker with draggable:true does not error if removed on mousedown', (t) => {
    const map = createMap(t);
    const marker = new Marker({draggable: true})
        .setLngLat([0, 0])
        .addTo(map);
    const el = marker.getElement();
    simulate.mousedown(el);
    simulate.mousemove(el, {clientX: 10, clientY: 10});

    marker.remove();
    t.ok(map.fire('mouseup'));
    t.end();
});

We have run into scenarios where we remove a draggable marker before `mouseup` is ever fired and, because mouseup/touchend never fired once, `_onUp` is called but the marker has already been torn down, leading to errors.

Ensuring these listeners are deregistered when tearing down the marker will ensure that doesn't happen.
@vbud
Copy link
Contributor Author

vbud commented Oct 19, 2018

@mollymerp tests added!

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

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

✨thanks again @vbud !

@mollymerp mollymerp merged commit 1d734ca into mapbox:master Oct 19, 2018
@vbud vbud deleted the patch-1 branch October 19, 2018 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants