Repository navigation
fix(navigation): keep the map and its follow camera through native navigation - #767
Merged
Merged
Conversation
…vigation In the installed app, turn-by-turn navigation showed the route overview with no position marker, and the camera never followed. useForegroundLocation memoised its callback on the whole mobile runtime context, which changes with every native snapshot. MapCanvas builds the map in an effect that depends on that callback, so the map was destroyed and rebuilt every few seconds while navigating, each time at the stored overview and with a fresh first-fix request. The nav camera created its marker and entered follow only when mapReady changed, which a rebuild does not do, so a trip started during a rebuild never got either. - useForegroundLocation depends only on authority, client and state. - The nav camera creates its marker without needing a map (the frame loop attaches it to the current one) and enters follow again when a new map instance appears, but not on a style reload of the same map. - MobileRuntimeProvider applies bridge snapshots and events when they arrive instead of inside a state updater, which React runs while rendering and which updated store subscribers mid-render.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 and why
In the installed app, turn-by-turn navigation showed the whole route as an overview, with no position marker, and the camera never followed. The native session itself was fine: it accepted fixes and sent the page complete progress (snapped position, distance along the route, bearing) every few seconds.
The page rebuilt its map on every one of those updates.
useForegroundLocationmemoised its callback on the whole mobile runtime context, and that context changes with every native snapshot, because it carries the read model.MapCanvasbuilds the map in an effect that depends on that callback, so while navigating the map was destroyed and rebuilt every few seconds. Each new map started at the stored overview and asked the shell for a fresh first fix (the bridge showed alocation.resultafter everysnapshot.update). The nav camera created its marker and entered follow only whenmapReadychanged, which a rebuild does not do, so a trip that started during a rebuild never got either. On the device the camera hook's marker ref wasnull, its follow-entry refs were never written, and a map canvas tagged before a snapshot was gone after it.useForegroundLocationdepends only on what decides where a fix comes from: authority, client and runtime state. Snapshots no longer rebuild the map.useNavCameracreates its marker without needing a map (the frame loop attaches it to the current one) and enters follow again when a new map instance appears, but not on a style reload of the same map. The camera now survives any rebuild, such as one after the shell handshake.MobileRuntimeProviderapplies bridge snapshots and events when they arrive. It used to apply them to the navigation store inside asetStateupdater, which React runs while rendering; React warned "Cannot update a component (NavigationRouteLayer) while rendering a different component (MobileRuntimeProvider)" on the device.Verification
lib/mobile,lib/navigation,components/navigationandcomponents/map: 1,603 passed.tscforapps/web, biome.Release and upgrade impact
Product impact: ordinary