[Bug] Marker crashes with "appendChild" error during rapid client-side navigation (React 19 / Next.js 16)
Nessuno ha ancora preso questa issue.
- #2585 di @officialasishkumar — chiusa senza merge
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- nextjs, react, typescript
- Ambito
- data-visualization, frontend
Direzione di ricerca
Inizia da modules/react-mapbox/src/components/marker.ts, in particolare dal useEffect attorno alla riga collegata, e riproduci la navigazione rapida lato client descritta nell'issue. Verifica la gestione suggerita rispetto al ciclo di vita di Marker e al comportamento di cleanup. Il lavoro è completato quando la navigazione rapida non produce più il crash di appendChild senza interrompere il normale montaggio e la rimozione di Marker.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 8.5k
- Fork
- 1.3k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di visgl/react-map-gl
-
DEFAULT_SETTINGS.maxBounds in @vis.gl/react-maplibre has 360° longitude span, triggers maplibre-gl-js#6148 crash via _updateSettings fallbackForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
visgl/react-map-gl#2591 · 2 commenti ·
-
[Bug] Mapbox geocoder example crashes: "i is not a function"Forse già presa @yuiseki l’ha presa 20 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
visgl/react-map-gl#2628 ·
-
[Bug] Scroll zoom stops short of maxZoom in controlled mode with MapLibreForse già presa @sviat-barbutsa l’ha presa 33 giorni fa. Apertabug
Difficoltà 3/5 Mezza giornata Idoneità per principianti 74/100
visgl/react-map-gl#2626 ·
-
[Bug] reuseMaps: Mapbox.reuse() infinite-loops (tab freeze) when the recycled map's container is the mount containerForse già presa @mikeyfarina l’ha presa 82 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
visgl/react-map-gl#2613 ·
-
feature
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
visgl/react-map-gl#2603 · 1 reazione ·
Tutte le issue di visgl/react-map-gl
Issue simili
-
accessibility area:ci ci-test level:low priority:high type:test
Difficoltà 2/5 1-3 ore Idoneità per principianti 71/100
skytuhua-org/Gen-V1#3132 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
drmrd/vernacular#1238 ·
I maintainer di solito rispondono entro 1 giorno
-
question
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
enhancement migration-prioritized
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Hudson-Pufferfish/local-party-console#136 ·
I maintainer di solito rispondono entro 1 giorno
-
priority:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno