mapbox / mapbox/mapbox-gl-js

Semantics of IControl.onAdd/onRemove are inconsistent

Open
#12,823 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

api :memo:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Semantics of `onAdd`: expected to create and return a DOM element which Map will add within its own div.

Semantics of `onRemove`: expected to remove its own DOM element.

Surprised this inconsistency hasn't been flagged before.

It seems to me that `map.removeControl(X)` should remove X, rather than relying on X to remove itself.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the IControl.onAdd and IControl.onRemove semantics, then trace map.removeControl(X) to understand which side currently owns removal of the DOM element. Done means the control lifecycle has consistent ownership semantics, with behavior matching the issue's expectation that removing a control removes X.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.