mapbox-web-integration-patterns
Official integration patterns for Mapbox GL JS across popular web frameworks (React, Vue, Svelte, Angular). Covers setup, lifecycle management, token handling, search integration, and common pitfalls. Based on Mapbox's create-web-app scaffolding tool.
Security Assessment
About mapbox-web-integration-patterns
This skill provides official patterns for integrating Mapbox GL JS into web applications across popular frameworks: React (the primary pattern), Vue, Svelte, Angular, Next.js, and vanilla JavaScript. It is based on Mapbox's create-web-app scaffolding tool and captures production-ready best practices. The problem it addresses is that GL JS is a stateful, WebGL-based library that must be initialized in the right lifecycle hook, kept out of the render path, and explicitly torn down; getting this wrong causes memory leaks, infinite re-render loops, and broken server-side rendering.
It documents version requirements (GL JS v3.x recommended, minimum v3.0.0, with v2-to-v3 migration notes such as the WebGL 2 requirement) and framework version compatibility, plus Mapbox Search JS packages. Core principles apply to every integration: initialize in the correct hook, store the map instance in a ref or component state rather than recreating it, always call map.remove() on cleanup, import the GL JS CSS, and handle tokens securely through environment variables. Framework-specific reference files show the useRef plus useEffect cleanup pattern for React, the 'use client' directive and NEXT_PUBLIC_ env vars for Next.js App Router, dynamic ssr:false imports for Pages Router, and equivalents for Vue, Svelte, Angular, web components, and vanilla JS, along with token-management and common-mistakes references and an evals set.
It targets frontend and full-stack developers embedding interactive Mapbox maps. Its security guidance is defensive: it consistently recommends storing access tokens in environment variables rather than hardcoding them, and it involves no destructive or risky operations.
FAQ
Which frameworks does this skill cover?
React (the primary pattern), Vue, Svelte, Angular, Next.js (App and Pages Router), vanilla JavaScript, and web components, all based on Mapbox's create-web-app scaffolding.
What version of Mapbox GL JS is recommended?
v3.x (minimum v3.0.0). It notes the v2-to-v3 migration requires WebGL 2, removes the optimizeForTerrain option, and improves TypeScript types and tree-shaking, with no breaking changes to core initialization.
How does it recommend handling access tokens?
Securely through environment variables rather than hardcoding, for example import.meta.env.VITE_MAPBOX_ACCESS_TOKEN with Vite, process.env.REACT_APP_MAPBOX_TOKEN with Create React App, or NEXT_PUBLIC_MAPBOX_TOKEN with Next.js.
What is the most important rule for avoiding bugs?
Initialize the map once in the correct lifecycle hook, store the instance in a ref rather than recreating it on render, and always return a cleanup function that calls map.remove() to prevent memory leaks.
How do I use Mapbox maps with Next.js?
In the App Router, mark the component with the 'use client' directive since maps need browser APIs and use NEXT_PUBLIC_ env vars; in the legacy Pages Router, dynamically import the map component with ssr:false and a loading state.
All Files
11 filesInstall mapbox-web-integration-patterns
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
mapbox/mapbox-agent-skills