Repository navigation
fix: recreate maps when Activity becomes visible again - #2625
Open
sviat-barbutsa wants to merge 3 commits into
Open
sviat-barbutsa wants to merge 3 commits into
sviat-barbutsa wants to merge 3 commits into
Conversation
[Medium impact] The PR appears safe to merge. SummaryRecreates Mapbox and MapLibre maps when React Activity shows them again.
Reviews (3) · Last reviewed commit: "Clean up the recycled map after the Mapb..." · Reviewed by Greptile |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Markercould 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
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
mapInstancestate tonullon unmount/effect cleanup in bothreact-mapboxandreact-maplibre. This prevents child components from attempting to attach to destroyed or recycled instances when an effect disconnects and reconnects under React 19'sActivitycomponent.Updates the map reuse logic to guard against reparenting child nodes when the container element has not changed, and shifts
[mapboxgl-children]element cleanup fromrecycle()toreuse(). Development dependencies and test runners are also upgraded to React 19 to add regression tests for hidden and visibleActivitytransitions.Reviewed by Cursor Bugbot for commit 7ac92eb. Bugbot is set up for automated code reviews on this repo. Configure here.