Map dimensions are incorrect when shadow root is present
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
It seems [`_updateContainerDimensions`](https://github.com/mapbox/mapbox-gl-js/blob/596da6b8e6bf4ff2530e82fce7edefb4aea33a17/src/ui/map.ts#L3993) function is implemented in such a way that if the map is placed inside the Shadow DOM, and the scaling transformation is applied outside of shadow root, then calculated canvas size will be incorrect.
Reproduction:
https://jsbin.com/kuxaveliri/1/edit?html,output
Note that the dimensions of the map inside the `#container` are halved because there is a scaling transform on the `body`.
We found a hot fix for our case, that seems to be working correctly (it is also attached in the repro above):
```js
map._updateContainerDimensions = function () {
if (!this._container) return
const width = this._container.offsetWidth || 400
const height = this._container.offsetHeight || 300
this._containerWidth = width
this._containerHeight = height
}
```
**mapbox-gl-js version**: 3.8.0
**browser**: Firefox 133.0, Chrome 131.0.6778.86
### Steps to Trigger Behavior
1. Place a map inside the shadow DOM
2. Apply CSS transform outside of the shadow root
3. Observe the map is scaled incorrectly, resulting in the doubled scaling factor.
### Link to Demonstration
https://jsbin.com/kuxaveliri/1/edit?html,output
### Expected Behavior
The map fully occupies the scaled `#container`, no matter if the shadow DOM is used or not.
### Actual Behavior
If the shadow DOM is present, the map is scaled incorrectly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/ui/map.ts at _updateContainerDimensions and reproduce the behavior using the linked JSBin, comparing a map inside and outside a shadow root with the body transform applied. Verify the container and canvas dimensions against the expected scaled #container size, and confirm the map fully occupies it in both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100