[Bugfix] JS error on control removal #259
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
#249
β Type of change
π Description
When unmounting the
MapboxMapcomponent, we call themap.remove()methods, which loops over all added controls and removes them. But, controls are also removed inside theuseControlcomposable on unmount. This works fine with some controls but fails with theMapboxGeocodercomponent: it is first removed when callingmap.remove()and then we try to remove it a second time, which fails because the container DOM element has already been removed (see https://github.com/mapbox/mapbox-gl-geocoder/blob/66c236f1f52d69bc2e2b5b8fb3ecc5255fc46acf/lib/index.js#L396-L408).The fix is simple : we check if the map still has the control we want to remove before removing it, preventing calling the control's
onRemovemethod twice.π Checklist