Skip to content

fix: recreate maps when Activity becomes visible again - #2625

Open
sviat-barbutsa wants to merge 3 commits into
visgl:masterfrom
sviat-barbutsa:fix-activity-map-reappear
Open

sviat-barbutsa wants to merge 3 commits into
visgl:masterfrom
sviat-barbutsa:fix-activity-map-reappear

Conversation

@sviat-barbutsa

@sviat-barbutsa sviat-barbutsa commented Oct 27, 2026 •

Copy link
Copy Markdown

What changed

React Activity keeps component state when it hides a route, but it cleans up and later reconnects effects. The map cleanup was destroying the underlying Mapbox or MapLibre instance while the stored map state still pointed to it. When the route appeared again, a child such as Marker could try to attach to that destroyed map and crash.

This clears the stored map state and context references during cleanup, so children remount only after a fresh map instance is ready. The fix covers both Mapbox and MapLibre.

I also updated the test runtime to React 19 and added Activity hide/show tests for both integrations. Each test checks that the map is recreated and its marker is attached again.

Verification

  • Activity regression tests: 2 passed
  • Full test suite: 86 passed
  • Mapbox and MapLibre type checks passed
  • Lint and build passed

Fixes #2588


Note

Low Risk
Low risk bug fix scoped to component lifecycle cleanup and container reparenting during map reuse, with no breaking API changes.

Overview
Resets the internal mapInstance state to null on unmount/effect cleanup in both react-mapbox and react-maplibre. This prevents child components from attempting to attach to destroyed or recycled instances when an effect disconnects and reconnects under React 19's Activity component.

Updates the map reuse logic to guard against reparenting child nodes when the container element has not changed, and shifts [mapboxgl-children] element cleanup from recycle() to reuse(). Development dependencies and test runners are also upgraded to React 19 to add regression tests for hidden and visible Activity transitions.

Reviewed by Cursor Bugbot for commit 7ac92eb. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Recreates Mapbox and MapLibre maps when React Activity shows them again.

  • Maps create a fresh instance when an Activity route appears again.
  • Reused maps reconnect their React children after an Activity appears again.

Reviews (3) · Last reviewed commit: "Clean up the recycled map after the Mapb..." · Reviewed by Greptile

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Marker crashes with "appendChild" on Activity reappear when Next.js cacheComponents is enabled (production-only)

1 participant