mapbox / mapbox/mapbox-gl-js

instanceof check breaks mapbox-gl-js in multiframe environment

Open
#8,036 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

**mapbox-gl-js version**: 0.53.0

**browser**: chrome / safari

**culprit**: [map.js](https://github.com/mapbox/mapbox-gl-js/blob/master/src/ui/map.js#L346)

### Steps to Trigger Behavior
render mapbox inside new environment (eg. window.open)
1). create a popup (window.open)
2). use React.createPortal to render the map component
3). Render map inside component

### Link to Demonstration
https://codesandbox.io/s/qllpz89w39

### Expected Behavior
code doesnt throw an error because container check fails while container is actually of the correct type (HTMLElement)

### Actual Behavior
code throws an error because instanceof fails within different environments

more informatiion in this article:
[instanceof considered harmful](http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/)

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 at src/ui/map.js#L346 and reproduce the failure using the linked CodeSandbox with a map rendered in a window.open environment through React.createPortal. Verify the container check accepts the correct HTMLElement across browsing contexts without throwing, while preserving normal container validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.