Repository navigation
Description
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Version Number: 9.4.32-0
Reproducible in staging?: Yes
Reproducible in production?: No (Update: Yes)
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #95372
Email or phone of affected tester (no customers): testing210790@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Samsung a31
App Component: Other
Action Performed:
1.Login to the Expensify app
2.Enable location permission for Expensify and select "Allow only while using the app"
3.Tap the FAB button
4.Tap "Track expense"
5.Open the Manual Distance Map
6.Allow the app to load the map
7.Sign out from the account
8.Sign in again with the same account
9.Open the Manual Distance Map again
Expected Result:
The Manual Distance Map displays the user's current location based on the device location permission.
Actual Result:
The Manual Distance Map displays San Francisco as the default location after signing in again, instead of the user's current location.
Workaround:
Unknown
Platforms:
- Android: App
- Android: mWeb Chrome
- iOS: App
- iOS: mWeb Safari
- iOS: mWeb Chrome
- Windows: Chrome
- MacOS: Chrome Safari
Screenshots/Videos
Bug7203915_1783626730569.WhatsApp_Video_2026-07-09_at_11.34.01_AM__1_.mp4
Applause Internal Information
Exported by: Murugesan Natarajan
Bug ID: 7203915
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022075404316054712715
- Upwork Job ID: 2075404316054712715
- Last Price Increase: 2026-07-10
Issue Owner
Current Issue Owner: @DylanDylannMetadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
applause-bot commentedon Jul 10, 2026
While Applause doesn't embed attachments for this bug, here are the links for quick view:
https://platform.applause.com/services/links/v1/external/00eb557ae57873db57f71d1c687852f6f78529c16a01956f4de05e52cd677465
MelvinBot commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
This is a regression from #95372 (merged 2026-07-08, "Only read foreground location permissions without requesting them at the beginning") — the same PR this bug was caught against. That PR touched only
MapView.tsxandGPSMapView.tsx.The manual distance map centers on
userLocation ?? initialLocation, whereinitialLocationis the hardcoded default (San Francisco).userLocationis stored in Onyx (ONYXKEYS.USER_LOCATION), which is cleared on sign-out — so after re-login the map starts on the SF default and relies entirely on a one-shotuseFocusEffectto fetch the real location and update it.Before #95372, that effect called
getCurrentPosition(...)unconditionally, which internally calls the activerequestForegroundPermissionsAsync()— this forces expo-location to resolve the true OS authorization status and returnsgrantedwhen permission is allowed. #95372 replaced this with a passivegetForegroundPermissionsAsync()gate that runs first, and if it returns!granted, it clears the location and bails without ever callinggetCurrentPosition. Because the effect is guarded by auseRefthat flips tofalseafter one run, a single false-negative read is sticky — the map never retries and stays on SF.The passive read returns not-granted in the re-login scenario (the active request did not), which is why the map worked on the first open of a session but falls back to SF after signing out and back in.
Code evidence (SHA
7e966b4)userLocationis null:MapView.tsx:69-70useRefgate + the new passive-permission check that clears location on!granted:MapView.tsx:107-144getCurrentPositionuses the activerequestForegroundPermissionsAsync()(the pre-Only read foreground location permissions without requesting them at the beginning #95372 path):getCurrentPosition/index.ts:11USER_LOCATIONis not in the sign-out keys-to-preserve list, soOnyx.clearwipes it on logout (src/libs/actions/Session/index.ts— noUSER_LOCATIONreference).Why first-load works but re-login doesn't: both start with
userLocation === nulland a freshMapViewmount. The only behavioral difference is the permission call — the active request resolvesgrantedand fetches the position; the passive read reports not-granted, clears the location, and the one-shot ref prevents any retry.What changes do you think we should make in order to solve the problem?
Stop treating a passive
!grantedread as "permission denied → wipe location." The goal of #95372 was only to avoid prompting the user when the map opens — not to stop reading an already-granted location. Preferred fix (inMapView.tsx):PermissionStatus.DENIEDas the fallback trigger. Forgranted(or an undetermined-but-previously-allowed status), still callgetCurrentPositionso an already-allowed permission isn't discarded. This keeps "don't prompt on open" while restoring the location read.Secondarily (defense-in-depth, not the root fix): consider adding
ONYXKEYS.USER_LOCATIONto the sign-out keys-to-preserve list so the last known location survives logout instead of resetting to SF.What alternative solutions did you explore? (Optional)
Making
getCurrentPositionitself use the passivegetForegroundPermissionsAsync()internally and lettingMapViewcall it unconditionally as before — same "read, don't request" behavior without a separate gate. NoteGPSMapView.tsxhas the same passive-read pattern but self-heals via a re-check on app focus, so it doesn't exhibit the sticky failure;MapView.tsxhas no such re-check.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/95774)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal.
MobileMage commentedon Jul 10, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-07-10 02:20:14 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On native (Android and iOS), after signing out and signing back in with the same account, the manual distance map opens centered on San Francisco instead of the device's current location, even though the OS location permission is still granted. Opening the map before signing out works correctly; only the sign-out/sign-in cycle reproduces it. This is a regression introduced by PR #95372 (merged as
a31422e), which is why it reproduces in staging but not production.What is the root cause of that problem?
Sign-out runs
Onyx.clearandONYXKEYS.USER_LOCATIONis not in the preserved keys inSignInRedirect.ts, so after signing back inuserLocationisnull.MapViewthen falls back toinitialLocation, whichDistanceRequestFooterbuilds fromCONST.MAPBOX.DEFAULT_COORDINATE([-122.4021, 37.7911], San Francisco) when there are no waypoints:App/src/components/MapView/MapView.tsx
Lines 69 to 70 in 7e966b4
For the map to show the real location, the focus effect must re-fetch it via
getCurrentPositionand callsetUserLocation. PR #95372 rewrote that effect. It now flips the one-shot guardshouldInitializeCurrentPosition.current = falsesynchronously (line 111), then defers the actual fetch behind an asynchronous permission read,getForegroundPermissionsAsync().then(...), guarded by anignoreflag:App/src/components/MapView/MapView.tsx
Lines 120 to 124 in 7e966b4
The effect returns a cleanup that sets
ignore = true:App/src/components/MapView/MapView.tsx
Lines 146 to 148 in 7e966b4
useFocusEffectre-runs its callback whenever theuseCallbackdependencies change while the screen is focused, and on each re-run it first invokes the previous cleanup.setCurrentPositionToInitialStatedepends oninitialLocation(derived from theinitialStateprop), andshouldPanMapToCurrentPositiondepends onwaypoints. On a fresh sign-in, Onyx is re-hydrating (transaction, mapbox token, waypoints) so these dependencies change identity within the tens-of-milliseconds native window ofgetForegroundPermissionsAsync. When that happens the cleanup firesignore = true, aborting the pending.thenbeforegetCurrentPositionruns, and the re-run of the effect immediately returns at line 107 because the one-shotshouldInitializeCurrentPositionguard was already consumed. The location fetch is therefore permanently skipped:setUserLocationis never called,userLocationstaysnull, andcurrentPositionremains the SF fallback. Web is unaffected becauseMapViewImpl.web.tsxwas not touched by the PR and still callsgetCurrentPositiondirectly with no async permission gate and noignoreabort, which is exactly why the issue is flagged for Android and iOS but not web.What changes do you think we should make in order to solve the problem?
In
src/components/MapView/MapView.tsx, remove theignorecancellation from the focus effect so a focus-effect teardown/re-run no longer aborts the in-flight permission read and location fetch. The async callbacks here only write to Onyx (setUserLocation/clearUserLocation), never React component state, so completing them after a blur or unmount is harmless. This matches the pre-PR behavior, which had no such guard and worked correctly. ThegetForegroundPermissionsAsyncgate is kept, so the PR's goal of never triggering an OS prompt on open is preserved.With the abort gone, the first effect run consumes the one-shot guard, kicks off the permission read, and always completes it; later focus re-runs early-return harmlessly at the guard. Once permission is confirmed granted,
getCurrentPositionresolves andsetUserLocationwrites the real coordinates, so the map pans off the SF fallback. This keeps the intended lifecycle contract: sign-out clearsUSER_LOCATION(correct, since one account's cached location must not persist into another session), and sign-in reliably re-triggers the fetch that repopulates it. Offline behavior is unchanged because the effect still early-returns whenisOfflineis true.What alternative solutions did you explore? (Optional)
Preserving
USER_LOCATIONacross sign-out by adding it tokeysToPreserveinSignInRedirect.tswas rejected: it would leak one account's location into the next session and still show a stale position rather than the current one. Keepingignorebut deferringshouldInitializeCurrentPosition.current = falseinto the resolved.thenwas also rejected because it lets multiple focus re-runs fire concurrent permission reads and fetches; dropping the abort is simpler and mirrors the working web implementation.aswin-s commentedon Jul 10, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Android (and iOS), after signing out and signing back in with location permission still set to "Allow only while using the app", opening the Manual Distance Map shows San Francisco as the default location instead of the user's current device location. Expected: the map should center on the user's current location whenever the permission is granted, regardless of whether it is the first sign-in or a re-sign-in during the same app session.
What is the root cause of that problem?
Regression from PR #95372. In src/components/MapView/MapView.tsx:121-143 the
useFocusEffectwas changed to gategetCurrentPositionongetForegroundPermissionsAsync().then(({granted}) => ...). On the!grantedbranch (line 125-131) it now synthesizes aPERMISSION_DENIEDerror and callssetCurrentPositionToInitialState, which at line 91-99 invokesclearUserLocation()— wiping the OnyxUSER_LOCATION(src/libs/actions/UserLocation.ts:13-15). On a re-sign-in,getForegroundPermissionsAsyncon Android can resolve withgranted: falseon the first call after the app re-mounts the map (the runtime permission state is not yet re-hydrated in expo-location for the fresh module instance even though the OS grant is still "while in use"). The map then falls back toinitialLocationderived frominitialState.location, whichDistanceRequestFooter.tsx:107-109sets toCONST.MAPBOX.DEFAULT_COORDINATE=[-122.4021, 37.7911](San Francisco) when there are no waypoints. Pre-PR code calledgetCurrentPositionunconditionally, so the OS-level grant was honored directly and the stale/undefined permission read never had a chance to short-circuit the location fetch.What changes do you think we should make in order to solve the problem?
!grantedfromgetForegroundPermissionsAsyncas a permission denial. Only clear the cached user location whengetCurrentPosition's error callback (setCurrentPositionToInitialState) actually receives a realPERMISSION_DENIEDerror from the geolocation API. Instead, attemptgetCurrentPositionand let its native error path decide.grantedis false, still callgetCurrentPosition(it is a no-op / errors cleanly if truly denied) but do NOT synthesize a fakePERMISSION_DENIEDerror that clears the last-known user location.getForegroundPermissionsAsyncreturnsgranted: falseon mount, retry once after the map becomes ready (or on next focus) before deciding to clear cached location, since expo-location's cached status can lag the OS grant right after an auth navigation reset.USER_LOCATIONOnyx key across sign-out (or explicitly clear on sign-in) so the fallback path never lands on the SF default when the OS grant is intact.MapViewwithinitialState.location = DEFAULT_COORDINATE, mocksgetForegroundPermissionsAsyncto resolvegranted: falseonce thengranted: true, and assertssetUserLocationis called (notclearUserLocation).What alternative solutions did you explore? (Optional)
shivang-goliyan commentedon Jul 10, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-07-10 02:37:56 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Android and iOS, opening the Manual Distance Map for a track expense should center on your current location once you've allowed location access. After you sign out and sign back in with the same account, the map instead centers on San Francisco even though the permission is still granted. It only clears up once the map component fully remounts.
What is the root cause of that problem?
The map center comes from
src/components/MapView/MapView.tsx:70,const currentPosition = userLocation ?? initialLocation.userLocationis the OnyxUSER_LOCATIONvalue; when it's null the map falls back toinitialLocation, which for a fresh manual map with no waypoints isCONST.MAPBOX.DEFAULT_COORDINATE([-122.4021, 37.7911], San Francisco). So "shows SF" meansuserLocationis null.USER_LOCATIONisn't inKEYS_TO_PRESERVE(src/libs/actions/App.ts), so sign-out'sOnyx.clear()wipes it. That clear on logout is old and intended. After re-login the map is supposed to re-fetch the location and write it back throughsetUserLocation, but it doesn't.The reason it doesn't is the location effect only runs once per mount.
shouldInitializeCurrentPosition = useRef(true)is consumed on the first focus (MapView.tsx:107-111), then the effect does a read-onlygetForegroundPermissionsAsync().then(...)and, if granted, callsgetCurrentPosition→setUserLocation. During the HybridApp sign-in transition this first pass gets lost: either the permission read resolvesgranted: falseright after re-init and hits the!grantedbranch that clears back to SF, or a blur during the transition fires theignore = truecleanup (MapView.tsx:146-148) and cancels the in-flight fetch. Because the one-shot ref is already spent, the effect early-returns on the next focus and never retries, soUSER_LOCATIONstays null.This is a regression from PR #95372 (merge
a31422e794d, 2026-07-08), which is the PR named in the issue's QA field and matches "staging: Yes, production: No." That PR replaced the old unconditionalgetCurrentPosition(which internally calledrequestForegroundPermissionsAsyncand forced a native round-trip that came back granted) with the read-onlygetForegroundPermissionsAsyncgate, to fix #93747 (the map popping an unsolicited OS permission prompt on open). The gate itself is correct; the problem is that combined with the pre-existing one-shot ref, there's no retry when that first read-and-fetch misses. Worth noting the siblingGPSMapView.tsxdoesn't have this bug: it has no one-shot ref, re-reads permission on every focus, and re-checks on app-foreground viauseAppFocusEvent(GPSMapView.tsx:60-87).What changes do you think we should make in order to solve the problem?
Make MapView's location fetch retry-capable instead of one-shot, mirroring
GPSMapView, while keeping the read-only permission gate so we don't reopen #93747.shouldInitializeCurrentPositionref (MapView.tsx:72) and its early-return/consume block (MapView.tsx:107-111), souseFocusEffectre-runs the existinggetForegroundPermissionsAsync → getCurrentPosition → setUserLocationchain on every focus. The ref's original job was to avoid re-panning the camera on refocus, but that's already handled byshouldPanMapToCurrentPosition()(MapView.tsx:86-89), which returns false once the user has dragged the map or any waypoint exists. So removing the ref won't pan away from user-set state.useAppFocusEvent(src/hooks/useAppFocusEvent, already used by GPSMapView, not yet imported here) to re-read permission and re-fetch when the app returns to the foreground. This covers the background-to-foreground variant and also fixes a smaller existing gap: if you grant permission in OS settings while the map is open, MapView currently never re-checks.MapView.tsxis the single native file behind both Android and iOS, so both reported platforms are covered. The web renderer (MapViewImpl.web.tsx) still requests location directly and was untouched by #95372, so web/mWeb stay unaffected, matching the unchecked boxes.I'd also add a Jest test for the retry path, since nothing in
src/components/MapView/currently exercises the permission-then-fetch effect: mockgetForegroundPermissionsAsyncto resolve{granted: false}first then{granted: true}, mockgetCurrentPosition, mount with empty waypoints and nullUSER_LOCATION, and assertsetUserLocationeventually fires so the map isn't left onDEFAULT_COORDINATE.What alternative solutions did you explore? (Optional)
Adding
USER_LOCATIONtoKEYS_TO_PRESERVEso logout doesn't wipe it. I rejected this because it persists one account's device location across a different sign-in, doesn't restore the "refresh to actual current location" behavior, and has a wider blast radius than a map-only fix.Reverting #95372 outright. That brings back the unsolicited OS permission prompt on map open, which is exactly the bug #95372 fixed, so keeping the read-only gate and fixing the retry mechanism is the better route. Changing
DEFAULT_COORDINATEor the caller fallback isn't right either, since SF is the intended empty-state default and the real defect is the missing re-fetch.ahmdshrif commentedon Jul 10, 2026
🚨 Edited by proposal-police: This proposal was edited at 2026-07-10 02:21:51 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
After signing out and back in, the manual distance map on Android/iOS shows the San Francisco default location instead of the user's current location, even though location permission is granted.
What is the root cause of that problem?
Regression from PR
#95372— specifically its commit "Implement cleanup for location permission handling in MapView component" (52fa828), which added a cancellation flag to an effect already guarded by a once-only ref. A cancelled fetch is never retried:useFocusEffectthat early-returns ifshouldInitializeCurrentPosition.currentisfalse, and sets itfalsebefore starting the async fetch —App/src/components/MapView/MapView.tsx
Lines 107 to 111 in 7e966b4
#95372wrapped the fetch ingetForegroundPermissionsAsync().then(...)withlet ignore = falseplus a cleanupignore = true; both the permission result and the position callback bail onceignoreis set —App/src/components/MapView/MapView.tsx
Lines 120 to 148 in 7e966b4
getCurrentPositionawaits the permission request and a fresh GPS fix —App/src/libs/getCurrentPosition/index.ts
Lines 10 to 25 in 7e966b4
useFocusEffectruns the cleanup and re-runs the effect on blur or whenever the callback identity changes; the callback depends onshouldPanMapToCurrentPosition(new whenever thewaypointsarray identity changes) andsetCurrentPositionToInitialState(new wheneverinitialStatechanges) —App/src/components/MapView/MapView.tsx
Line 149 in 7e966b4
initialState/waypointsare rebuilt from the draft transaction inDistanceRequestFooter—App/src/components/DistanceRequest/DistanceRequestFooter.tsx
Lines 103 to 118 in 7e966b4
USER_LOCATION(not in the preserve list —App/src/libs/actions/SignInRedirect.ts
Lines 53 to 62 in 7e966b4
currentPosition = userLocation ?? initialLocationfalls back toCONST.MAPBOX.DEFAULT_COORDINATE(San Francisco) —App/src/components/MapView/MapView.tsx
Lines 69 to 70 in 7e966b4
App/src/CONST/index.ts
Line 6046 in 7e966b4
Structural cause: the cancellation added by
#95372is inconsistent with the pre-existing once-only guard — the guard marks initialization "done" before any result was applied. Pre-PR, an effect re-run was harmless (the un-cancelled callback still wrote the location); now it is fatal.This explains every symptom: staging-only (the PR isn't in production), Android + iOS App only (web's
MapViewImpl.web.tsxstill runs the fetch with no cancellation —App/src/components/MapView/MapViewImpl.web.tsx
Lines 102 to 124 in 7e966b4
userLocationleft to mask the cancelled fetch — before sign-out the location cached on first map load hides it).Blast radius: affected — manual distance map on Android and iOS (
DistanceMapView/index.android.tsxandindex.tsx→ nativeMapView). Verified unaffected — web/mWeb (no cancellation, above);ConfirmedRoute.tsx(always has waypoints →shouldPanMapToCurrentPosition()false → never fetches); the GPS tab'sGPSMapView.tsx(re-reads permission every focus, no once-only ref, camerafollowUserLocation) —App/src/components/MapView/GPSMapView.tsx
Lines 58 to 76 in 7e966b4
What changes do you think we should make in order to solve the problem?
In
MapView.tsx, mark initialization done only when a result is actually applied: delete the unconditionalshouldInitializeCurrentPosition.current = false;atApp/src/components/MapView/MapView.tsx
Line 111 in 7e966b4
!shouldPanMapToCurrentPosition()early-return):If the cleanup fires mid-fetch (dep change or blur), the ref stays
trueand the effect's next run retries; once a result lands, behavior is exactly today's fetch-once-per-mount. Regression safety: the no-OS-prompt gate, stale-write cancellation, and denied-path cache clearing from#95372all stay intact; the ref is local to this component; web is untouched.Why the obvious one-line fix does NOT work: reverting the cleanup commit (dropping
ignore) reintroduces exactly what it was added to prevent — a stale in-flight callback writingUSER_LOCATIONafter the screen blurred or a newer run started; and resetting the ref unconditionally in the cleanup changes the working case — after a successful fetch, every blur/refocus (e.g. returning from the waypoint-address RHP) would re-fetch and re-pan the map the once-only ref exists to prevent.What alternative solutions did you explore? (Optional)
52fa828— spot fix; reintroduces the stale-write race the PR intentionally guarded (above).didSettlelocal) — functionally equivalent to the headline, slightly larger diff.GPSMapView— removes the ref entirely but changes re-pan behavior on every refocus; broader than the regression warrants.abbasifaizan70 commentedon Jul 10, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Android/iOS, when a user opens the Manual Distance Map, signs out, signs back in with the same account, and opens the Manual Distance Map again, the map shows the San Francisco default location instead of the user's actual current location — even though location permission is still granted.
What is the root cause of that problem?
The map's current position comes from the
userLocationOnyx key, falling back to a hard-coded San Francisco coordinate when it isn't set yet:App/src/CONST/index.ts
Line 6046 in 9813012
App/src/components/MapView/MapView.tsx
Lines 60 to 70 in 9813012
ONYXKEYS.USER_LOCATIONis not in theKEYS_TO_PRESERVElist used when clearing Onyx on sign-out/sign-in, so it is wiped back tonullevery time the user re-authenticates, meaning the map has to fetch a fresh location again on the next visit.MapViewonly ever performs that fetch once per component lifetime, gated by a ref that is flipped tofalsebefore the async work even resolves. It calls the native geolocation module a single time viagetCurrentPosition, with no retry:App/src/components/MapView/MapView.tsx
Lines 101 to 150 in 9813012
getCurrentPositionitself is a one-shot call with no timeout handling or retry logic — any transient failure (e.g. the OS location provider not being warmed up yet right after the app relaunches following sign-in) is simply forwarded to the error callback:App/src/libs/getCurrentPosition/index.ts
Lines 10 to 25 in 9813012
That error callback,
setCurrentPositionToInitialState, only takes action forPERMISSION_DENIEDerrors and silently no-ops for anything else:App/src/components/MapView/MapView.tsx
Lines 91 to 99 in 9813012
Because
shouldInitializeCurrentPosition.currentwas already consumed (set tofalse) before the fetch ran, and it is never reset on failure, no further attempt is ever made for the lifetime of that screen. Combined withuserLocationhaving just been cleared by the sign-out/sign-in cycle,currentPositionpermanently falls back toinitialLocation, which for the Manual Distance Map is the San FranciscoDEFAULT_COORDINATE. The very first time the map is opened this doesn't reproduce because the app/GPS provider is already warm from being logged in for a while, so the single location fetch attempt succeeds; right after a fresh sign-in it is more likely to transiently fail, and that one failure is now permanent for the screen.What changes do you think we should make in order to solve the problem?
Reset the one-shot initialization guard when the location fetch fails for a reason other than a denied permission, so the map retries fetching the device location on the next focus instead of getting stuck on the San Francisco fallback for the rest of the screen's lifetime:
App/src/components/MapView/MapView.tsx
Lines 134 to 143 in 9813012
samranahm commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
The
IOURequestStepDistanceManualcomponent, which is responsible for displaying the manual distance map, fails to consistently show the user's current location after a sign-out and subsequent sign-in. This occurs because the component, or a sub-component it renders, does not reliably re-fetch or persist the user's last known location across session resets. When the app session is reset, the map component's initialization logic defaults to a hardcoded location (San Francisco) because it does not have access to a persistently stored last known location. Although the provided snippet forIOURequestStepDistanceManualshows extensive use of Onyx for various data, there is no explicit Onyx key or mechanism to store and retrieve the map's last known good coordinates, leading to the fallback default being used instead of the actual current location.What changes do you think we should make in order to solve the problem?
Introduce an Onyx key for last known location:
Define a new Onyx key, for example,
ONYXKEYS.LAST_KNOWN_LOCATION, to store the user's last successfully retrieved geographic coordinates. This key would hold an object like{latitude: number, longitude: number}.Update and persist location in
IOURequestStepDistanceManual:Within the
IOURequestStepDistanceManualcomponent, implement logic to fetch the current device location when the component mounts or becomes active. Upon successful retrieval of the current location, update theONYXKEYS.LAST_KNOWN_LOCATIONwith these coordinates usingOnyx.set(). This ensures that the most recent valid location is always available in persistent storage.App/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx
Lines 65 to 144 in 7e966b4
This step ensures that the user's current location is fetched and stored in Onyx, making it available across sessions.
Prioritize Onyx-stored location for map initialization:
Modify the map component's initialization logic within
IOURequestStepDistanceManualto first check thelastKnownLocationfrom Onyx. IflastKnownLocationis available, use its coordinates to set the map's initial view. The hardcoded San Francisco default should only be used as a last resort if no valid location can be retrieved from Onyx or a fresh fetch.App/src/pages/iou/request/step/IOURequestStepDistanceManual.tsx
Lines 65 to 144 in 7e966b4
This change ensures that the map initializes with the last known good location from Onyx, preventing it from defaulting to San Francisco after re-login.
What alternative solutions did you explore? (Optional)
Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.
melvin-bot commentedon Jul 10, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @FitseTLT (
External)19 remaining items
pvaghasiya087-has commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
The issue happens because
MapViewfalls back to the default map coordinate whenUSER_LOCATIONis unavailable after a fresh login.The current position selection logic in
src/components/MapView/MapView.tsxis:App/src/components/MapView/MapView.tsx
Line 70 in aa87e52
userLocationcomes fromONYXKEYS.USER_LOCATION. When the user signs out, this Onyx value is cleared. After signing back in,userLocationis empty, so the map usesinitialLocation.App/src/components/MapView/MapView.tsx
Line 60 in aa87e52
For Manual Distance Map, that fallback is created from:
App/src/components/ConfirmedRoute.tsx
Line 97 in aa87e52
which points to San Francisco.
The expected behavior depends on the map calling
getCurrentPosition()and saving the result throughsetUserLocation(), but the current implementation only attempts this during the initial focus lifecycle.The relevant flow in
MapView.tsxcurrently looks like:App/src/components/MapView/MapView.tsx
Line 72 in aa87e52
App/src/components/MapView/MapView.tsx
Lines 101 to 144 in aa87e52
The problem is that the initialization attempt can happen during the login transition when session data and native location state are still being restored.
If that first attempt does not update
USER_LOCATION, the ref has already changed:App/src/components/MapView/MapView.tsx
Line 111 in aa87e52
Future focus events skip the location refresh completely.
Therefore:
USER_LOCATION.What changes do you think we should make in order to solve the problem?
Instead of tying location synchronization to a single initialization attempt, make the location refresh depend on the actual state requirement:
If the map has no user location and permission is available, synchronize the location.
This keeps the existing permission behavior from PR #95372 (no automatic permission prompt), while making the location recovery reliable.
1. Replace the one-time initialization guard
Remove:
App/src/components/MapView/MapView.tsx
Line 72 in aa87e52
and the early return:
App/src/components/MapView/MapView.tsx
Lines 107 to 111 in aa87e52
The map should not permanently disable location recovery after one failed attempt.
2. Add a reusable location synchronization function
Inside
MapView.tsx, add:This keeps the important behavior:
3. Run synchronization when the map needs a location
Update the focus effect:
Now the flow becomes:
USER_LOCATION.4. Add app foreground synchronization
The same logic should run when the app returns to the foreground because location permission or native services can change while the app is inactive.
Reuse the same helper:
GPSMapView.tsxalready follows a similar lifecycle approach, so this makesMapViewconsistent with the existing location handling pattern.Testing changes
Add a regression test in the MapView test suite covering:
Case 1: Sign out → sign in → open Manual Distance Map
Mock:
Expected:
should be called.
The map should no longer use:
Case 2: Permission denied
Mock:
Expected:
Case 3: Existing user location
Mock:
Expected:
Alternative solutions considered
Preserve
USER_LOCATIONduring logoutThis would avoid the empty state, but it would keep an old location instead of retrieving the current device position. It also risks carrying location data between different sessions.
Remove the permission check completely
This would restore the old behavior, but it would reintroduce the permission prompt regression that the previous PR was intended to fix.
Only change the San Francisco fallback coordinate
This would hide the symptom but would not solve the missing location synchronization problem.
The safer fix is to make location restoration reliable after authentication changes while preserving the existing permission model.
MuhammadAhmadKhan-2 commentedon Jul 10, 2026
Proposal
What is the root cause of that problem?
The regression isn't simply caused by permission checks or the one-time initialization flag. The real issue is that location initialization has no lifecycle state. The map treats "started", "cancelled", "completed", and "failed" as the same state by consuming the initialization flag before the async permission/location flow finishes. After a sign-out/sign-in transition, any interrupted initialization leaves the component believing location has already been initialized, even though no valid location was ever obtained.
What changes do you think we should make in order to solve the problem?
Instead of relying on a boolean initialization ref, I'd introduce an explicit initialization state (
idle → loading → completed → failed). The map should only transition tocompletedafter successfully updatingUSER_LOCATIONor after handling an actual permission denial. If initialization is cancelled because of navigation, focus changes, or component re-rendering, it should return toidleso the next focus retries automatically. This keeps the permission behavior introduced in #95372 while eliminating race conditions and making the initialization flow deterministic instead of timing-dependent.What alternative solutions did you explore? (Optional)
I considered resetting the initialization flag or removing the cancellation logic entirely, but both approaches only address one race condition. A state-based lifecycle provides a single source of truth for location initialization, avoids duplicate requests, and prevents similar regressions if the permission or navigation flow changes again.
FitseTLT commentedon Jul 13, 2026
Asking question on the regressor pr
melvin-bot commentedon Aug 6, 2026
This issue has not been updated in over 15 days. @Julesssss, @FitseTLT, @DylanDylann eroding to Monthly issue.
P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!
DylanDylann commentedon Aug 19, 2026
@Julesssss Let's close this issue