[Bug] reuseMaps: Mapbox.reuse() infinite-loops (tab freeze) when the recycled map's container is the mount container
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu từ các điểm vào Mapbox.reuse() và recycle() được mô tả trong issue, sau đó so sánh các bản sao của chúng trong react-maplibre và mapbox-legacy. Tái hiện việc tái sử dụng cùng một container thông qua StrictMode hoặc điều hướng và chạy quy trình hồi quy trên trình duyệt được đề cập trong báo cáo; hoàn thành khi việc tái sử dụng không còn bị treo và các phần tử con của bản đồ vẫn khả dụng sau đó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
With reuseMaps enabled, Mapbox.reuse() reparents the pooled map's DOM into the new mount container:
const oldContainer = map.getContainer();
container.className = oldContainer.className;
while (oldContainer.childNodes.length > 0) {
container.appendChild(oldContainer.childNodes[0]);
}
If container === oldContainer, appendChild moves the first child to the end of the same node, so childNodes.length never decreases and the loop never terminates. The main thread pins at 100% CPU and the tab is unrecoverable — DevTools cannot attach, and on weaker machines the whole browser goes down.
The same-container case is real, including in production builds: any environment that re-runs the <Map> mount effect while the DOM node survives triggers it. We hit two:
- Production: Next.js 16 App Router back/forward navigation restores the previous page while re-running effects (React Activity semantics). The mount effect's cleanup ran
recycle()when the user navigated away; on back-navigationreuse()pops that instance and mounts it into the very container it was parked with. First back-navigation to the map page froze the tab, every time, for every visitor. - Development: React
<StrictMode>effect replay reaches the same state when themapLibimport is already cached — effect run 1's.thencreates/reuses the map, the replay cleanup recycles it, and effect run 2 reuses it into the same still-mounted container. (A first-ever mount survives only because theimport('mapbox-gl')resolves too slowly for run 1 to finish.)
Verified by pausing the wedged VM over CDP: execution sits inside reuse() with container === oldContainer → true.
Two related consequences we found while fixing it:
- On the same-container path, the
[mapboxgl-children]div is lost:recycle()removed it, and sincereuse()returns the same instance,setMapInstance()bails out onObject.isand React never re-inserts it — any plain-JSX map child silently disappears after the reuse. Mapbox.savedMapsis a global LIFO with no map↔container association, so with two simultaneously pooled maps a reuse can pop the other map and append its DOM into a container that still holds the first map's canvas.
Environment
@vis.gl/react-mapbox8.1.2 (viareact-map-glv8); the unguarded loop is also present on currentmaster, and byte-identical copies ship in@vis.gl/react-maplibreand themapbox-legacyentrymapbox-gl3.28.1, React 19.2, Next.js 16.3- Reproduces deterministically on the first back-navigation to a page rendering
<Map reuseMaps>behind a Suspense boundary
Suggested fix
Treat container === oldContainer as "already in place", and move the [mapboxgl-children] cleanup out of recycle() into the different-container branch so the surviving React tree keeps its children div:
static reuse(props, container) {
const that = Mapbox.savedMaps.pop();
if (!that) return null;
const map = that.map;
const oldContainer = map.getContainer();
if (oldContainer !== container) {
container.className = oldContainer.className;
oldContainer.querySelector('[mapboxgl-children]')?.remove();
while (oldContainer.childNodes.length > 0) {
container.appendChild(oldContainer.childNodes[0]);
}
}
// ...
}
recycle() {
Mapbox.savedMaps.push(this);
}
We've been running exactly this as a pnpm patch in production since 2026-08-27 with no regressions (including a browser test that walks pin → popup → team page → back). Happy to send it as a PR.
- Ngôn ngữ chính
- TypeScript
- Star
- 8.5k
- Fork
- 1.3k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của visgl/react-map-gl
-
DEFAULT_SETTINGS.maxBounds in @vis.gl/react-maplibre has 360° longitude span, triggers maplibre-gl-js#6148 crash via _updateSettings fallbackCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
visgl/react-map-gl#2591 · 2 bình luận ·
-
[Bug] Mapbox geocoder example crashes: "i is not a function"Có thể đã có người làm @yuiseki đã nhận 20 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
visgl/react-map-gl#2628 ·
-
[Bug] Scroll zoom stops short of maxZoom in controlled mode with MapLibreCó thể đã có người làm @sviat-barbutsa đã nhận 33 ngày trước. Đang mởbug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 74/100
visgl/react-map-gl#2626 ·
-
feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
visgl/react-map-gl#2603 · 1 reaction ·
-
[Bug] Prop `style` does not unset properties that become `undefined`Có thể đã có người làm @MohammadYusif đã nhận 140 ngày trước. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
visgl/react-map-gl#2595 · 3 bình luận ·
Tất cả issue của visgl/react-map-gl
Issue tương tự
-
accessibility area:ci ci-test level:low priority:high type:test
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 71/100
skytuhua-org/Gen-V1#3132 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
drmrd/vernacular#1238 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
enhancement migration-prioritized
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày