Migration from v4 to v5
v5 is a major internal refactor with zero breaking API changes. All existing imports, components, and composables work unchanged.
What Changed
Architecture
v5 consolidates duplicated code via factory patterns:
- Event listeners: 3 composables share one factory (
createEventListenerComposable) - Camera animations: 7 composables share one factory (
createCameraAnimation) - Layer composables: 4 composables share one factory (
createPropertySetter)
Result: 59% LOC reduction (5,432 → 2,208 LOC) with identical API surface.
Performance Fixes
- Memory leak fixed: Event listener cleanup functions now explicitly captured in
Maplibre.vue - Private API removed:
map._loadedreplaced with publicmap.isStyleLoaded() - GC pressure reduced:
useOptimizedComputeduses shallow equality by default (JSON.stringify only withdeepEqual: true)
SSR Compatibility
- All
window.setTimeoutreplaced withsetTimeout(SSR-safe) isBrowserguard added to map/marker/popup creation- Works with Nuxt SSR/SSG — wrap map components in
<ClientOnly>
New Exports
typescript
// Event handler types for consumers
import type {
MapClickHandler,
LayerClickHandler,
GeolocateHandler,
} from 'vue3-maplibre-gl';
// Factory utilities (advanced usage)
import {
EventListenerStatus,
AnimationStatus,
createEventListenerComposable,
createCameraAnimation,
LAYER_STYLE_CONFIG,
} from 'vue3-maplibre-gl';
// SSR guard
import { isBrowser } from 'vue3-maplibre-gl';Package Manager
Recommended package manager changed from yarn to bun:
bash
bun add vue3-maplibre-glAnimation Timeout (Opt-in)
Camera animation factories now support optional timeout to prevent hanging promises:
typescript
const { flyTo } = useFlyTo({ map: mapInstance });
// Timeout is opt-in — existing behavior (no timeout) is defaultUpgrade Steps
Update the package:
bashbun add vue3-maplibre-gl@latestNo code changes required — all v4 APIs work unchanged.
Optional: Use new event handler types for better TypeScript DX.
Testing Your Upgrade
bash
bun run type-check # Verify types
bun run build # Verify build
bun run test # Run tests