CSS warning shown when map container is not added to the DOM
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
When creating a new map instance using a container that is not yet added to the DOM we get this warning:
"This page appears to be missing CSS declarations for Mapbox GL JS, which may cause the map to display incorrectly. Please ensure your page includes mapbox-gl.css, as described in https://www.mapbox.com/mapbox-gl-js/api/."
If the container div is added to the DOM before the map is created the warning will not show. Beside this warning, it works perfectly fine to create a map for a container that is not in the DOM. We use this approach in our React setup, where the container is rendered at a later stage.
The issue seems to be with the current _detectMissingCSS() in src/ui/map.js
mapbox-gl-js version: 1.9.0
browser: Google Chrome
Steps to Trigger Behavior
const div = document.createElement('div');
// document.body.appendChild(div);
const map = new mapboxgl.Map({
container: div
});
Check the console to see the warning.
If the container div is added to the DOM before the map is created the warning will not show.
Link to Demonstration
https://jsfiddle.net/mastermaps/nz3Ld5ar/8/
Expected Behavior
Don't show the warning when the CSS is actually present.
Actual Behavior
The warning shows even though the CSS is loaded.
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 with _detectMissingCSS() in src/ui/map.js and reproduce the warning using a container div that has not yet been added to the DOM. Compare that behavior with a DOM-attached container and verify that the warning is suppressed when the CSS is present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100