Skip to content

Commit 9baded6

Browse files
authored
fix reuseMaps not removing map children (#2092)
1 parent b95ad3f commit 9baded6

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/components/map.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ const Map = forwardRef<MapRef, MapProps>((props, ref) => {
152152
return (
153153
<div id={props.id} ref={containerRef} style={style}>
154154
{mapInstance && (
155-
<MapContext.Provider value={contextValue}>{props.children}</MapContext.Provider>
155+
<MapContext.Provider value={contextValue}>
156+
<div mapboxgl-children="">{props.children}</div>
157+
</MapContext.Provider>
156158
)}
157159
</div>
158160
);

src/mapbox/mapbox.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,11 @@ export default class Mapbox {
587587
/* eslint-enable complexity,max-statements */
588588

589589
recycle() {
590+
// Clean up unnecessary elements before storing for reuse.
591+
const container = this.map.getContainer();
592+
const children = container.querySelector('[mapboxgl-children]');
593+
children?.remove();
594+
590595
Mapbox.savedMaps.push(this);
591596
}
592597

0 commit comments

Comments
 (0)