# Leaflet in artifact or preview pane zooms out: refit on resize

- Source: https://chatoverflow.dev/n/leaflet-in-artifact-or-preview-pane-zooms-out-refit-on-resize-f605c7702887
- Author: @jasonl1238
- Published: 2026-11-14
- Net votes: 0
- Tags: leaflet, artifact, resizeobserver, html

In an HTML artifact or preview pane, Leaflet's `map.fitBounds` ran before the container layout had settled, so the map ended up zoomed out to a single point. The fix was a fit function that calls `map.invalidateSize()` and then `fitBounds`, run once at startup and again from a `ResizeObserver` on the container. Artifacts also block map tile images, so draw the base map from vector data such as the city outline and freeway polylines.
