[Bug] Marker crashes with "appendChild" error during rapid client-side navigation (React 19 / Next.js 16)
Chưa có ai nhận issue này.
- #2585 của @officialasishkumar — đã đóng, không merge
Đá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
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- nextjs, react, typescript
- Lĩnh vực
- data-visualization, frontend
Hướng nghiên cứu
Bắt đầu với modules/react-mapbox/src/components/marker.ts, đặc biệt là useEffect xung quanh dòng được liên kết, và tái hiện thao tác điều hướng nhanh phía client được mô tả trong issue. Kiểm tra cách xử lý được đề xuất dựa trên vòng đời của Marker và hành vi cleanup. Được xem là hoàn tất khi thao tác điều hướng nhanh không còn gây ra lỗi crash appendChild mà không làm hỏng việc mount và gỡ bỏ Marker thông thường.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
The Marker component crashes with Cannot read properties of undefined (reading 'appendChild') during rapid client-side navigation (e.g., quickly navigating between a random page and a page that contains a <Map> with <Marker> children).
Expected Behavior
No response
Steps to Reproduce
TL:DR steps to reproduce:
Quickly navigate back and forth between pages which contain a <Map> with <Marker> children.
Steps to Reproduce
- Create a Next.js 16 app with React 19
- Page A: a list page (no map)
- Page B: a detail page with containing children
- Navigate rapidly between Page A and Page B using client-side navigation (clicking links, not full page loads)
- After a few rapid back-and-forth navigations, the error appears
Root Cause
The Marker component's useEffect at marker.ts#L86 calls marker.addTo(map.getMap()) with [] deps. During rapid unmount/remount cycles in React 19, the new mount's useEffect can fire before the previous mount's cleanup has run. At that point, mapbox-gl's Map instance still exists but its internal DOM container sub-elements have been torn down, causing marker.addTo() to fail when it tries to appendChild into a destroyed container.
Through instrumentation, I confirmed:
map.getMap()returns a validMapinstance (truthy)map._containerexists (truthy)- But inside
marker.addTo(), deeper container child elements are undefined - The error is intermittent and depends on navigation speed
Suggested Fix
Wrap marker.addTo(map.getMap()) in a try-catch in the useEffect
useEffect(() => {
try {
marker.addTo(map.getMap());
} catch {
// Map container was destroyed during rapid navigation — safe to ignore
return;
}
return () => {
marker.remove();
};
}, []);
Environment
- react-map-gl: 8.1.0 (via @vis.gl/react-mapbox)
- mapbox-gl: 3.11.0
- React: 19.1.0
- Next.js: 16.2.2 (App Router, Turbopack)
- Browser: Chrome
Logs
No response
- 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 ·
-
[Bug] reuseMaps: Mapbox.reuse() infinite-loops (tab freeze) when the recycled map's container is the mount containerCó thể đã có người làm @mikeyfarina đã nhận 82 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
visgl/react-map-gl#2613 ·
-
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 ·
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