[Bug] Marker crashes with "appendChild" error during rapid client-side navigation (React 19 / Next.js 16)
まだ誰も着手していません。
- #2585 @officialasishkumar による — マージされずにクローズ
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- nextjs, react, typescript
調査の方向性
modules/react-mapbox/src/components/marker.ts から始め、特に関連する行の周辺にある useEffect を確認し、issue に記載されたクライアント側の高速なナビゲーションを再現してください。提案された処理を、Marker のライフサイクルとクリーンアップの動作に照らして確認してください。高速なナビゲーションで appendChild のクラッシュが発生しなくなり、Marker の通常のマウントと削除を壊していなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- TypeScript
- スター
- 8.5k
- フォーク
- 1.3k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
visgl/react-map-gl のほかの issue
-
DEFAULT_SETTINGS.maxBounds in @vis.gl/react-maplibre has 360° longitude span, triggers maplibre-gl-js#6148 crash via _updateSettings fallback再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
visgl/react-map-gl#2591 · コメント 2 件 ·
-
[Bug] Mapbox geocoder example crashes: "i is not a function"対応中かも @yuiseki が 20 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
visgl/react-map-gl#2628 ·
-
[Bug] Scroll zoom stops short of maxZoom in controlled mode with MapLibre対応中かも @sviat-barbutsa が 33 日前に担当しました。 オープンbug
難易度 3/5 半日 初心者へのやさしさ 74/100
visgl/react-map-gl#2626 ·
-
[Bug] reuseMaps: Mapbox.reuse() infinite-loops (tab freeze) when the recycled map's container is the mount container対応中かも @mikeyfarina が 82 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
visgl/react-map-gl#2613 ·
-
feature
難易度 5/5 1週間以上 初心者へのやさしさ 42/100
visgl/react-map-gl#2603 · リアクション 1 件 ·
visgl/react-map-gl の issue をすべて見る
似ている issue
-
accessibility area:ci ci-test level:low priority:high type:test
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
skytuhua-org/Gen-V1#3132 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
drmrd/vernacular#1238 ·
メンテナーはふだん 1 日以内に返信
-
question
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
enhancement migration-prioritized
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Hudson-Pufferfish/local-party-console#136 ·
メンテナーはふだん 1 日以内に返信
-
priority:medium
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信