Skip to content

Fix null dereference in onRemove when container is detached - #561

Open
cpruijsen wants to merge 1 commit into
mapbox:mainfrom
cpruijsen:fix/issue-480
Open

Fix null dereference in onRemove when container is detached#561
cpruijsen wants to merge 1 commit into
mapbox:mainfrom
cpruijsen:fix/issue-480

Conversation

@cpruijsen

Copy link
Copy Markdown

onRemove throws when the geocoder's container is no longer in the DOM. lib/index.js calls
this.container.parentNode.removeChild(...) unconditionally, and parentNode is null once something
else has already detached the container. Removing the map first does exactly that, so the ordinary
teardown order of map then control throws on the second step.

This checks parentNode before removing. A container with no parent needs no removal, so there is
nothing to do in that case and the rest of the teardown, the moveend handler and the marker,
continues rather than being skipped by the throw.

The test removes the map and asserts onRemove does not throw.

Fixes #480

When a map is removed before the geocoder control is removed (e.g.
map.remove() followed by map.removeControl(geocoder)), the geocoder's
container is already detached from the DOM and parentNode is null,
causing a TypeError on removeChild. Guard the removal so onRemove is
safe to call after the container has been detached.

Fixes mapbox#480
@cpruijsen
cpruijsen requested a review from a team as a code owner September 13, 2026 23:26
@cpruijsen
cpruijsen requested review from ibesora and removed request for a team September 13, 2026 23:26
@ox-security

ox-security Bot commented Sep 13, 2026

Copy link
Copy Markdown

OX Security Logo

OX Security reviewed this pull request — nothing to fix.

No issues found

Branch fix/issue-480main

View scan in OX Security →

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 this pull request may close these issues.

Potential null dereference in onRemove()

1 participant