Skip to content

Commit

Permalink
fix reuseMaps not removing map children (#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
lh0x00 authored Jan 7, 2023
1 parent b95ad3f commit 9baded6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ const Map = forwardRef<MapRef, MapProps>((props, ref) => {
return (
<div id={props.id} ref={containerRef} style={style}>
{mapInstance && (
<MapContext.Provider value={contextValue}>{props.children}</MapContext.Provider>
<MapContext.Provider value={contextValue}>
<div mapboxgl-children="">{props.children}</div>
</MapContext.Provider>
)}
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions src/mapbox/mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,11 @@ export default class Mapbox {
/* eslint-enable complexity,max-statements */

recycle() {
// Clean up unnecessary elements before storing for reuse.
const container = this.map.getContainer();
const children = container.querySelector('[mapboxgl-children]');
children?.remove();

Mapbox.savedMaps.push(this);
}

Expand Down

0 comments on commit 9baded6

Please sign in to comment.