Repository navigation
Remove OnyxUtils.get() from GPSTripStateChecker (use useOnyx) #98703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On iOS,
checkAndCleanGpsNotification()awaitsliveActivityManager.listAll(), so this closure can become stale while it is suspended. If the hydrated state is not tracking and the user starts or resumes a trip before that call finishes, this branch still sees the oldfalsevalue, detects the newly started background task, and stops it while Onyx remainsisTracking: true, causing the trip to stop collecting locations. The removedOnyxUtils.get()ran after this await and observed the latest state; retain the latest subscribed value in a ref or otherwise verify the current tracking state after cleanup before stopping the task.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not something introduced by this PR so I'd leave as is.
@MelvinBot confirm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly agree it's fine to leave as-is, with one nuance so the call is made with eyes open.
The check-then-act race itself is pre-existing. Even before this PR, once the handler read
isTracking: falsethere was still anawait(hasStartedLocationUpdatesAsync, index.native.tsx:51) beforestopLocationUpdatesAsync, index.native.tsx:53 — a trip started in that gap would have been wrongly stopped too. So the class of race isn't new.But strictly, this PR does slightly widen the window. The old
OnyxUtils.get()read afterawait checkAndCleanGpsNotification(), whereas the new code reads the closure snapshot captured before it (index.native.tsx:48→50). On iOS that cleanup awaitsliveActivityManager.listAll(), index.ios.ts:165, so that native call is now inside the stale window where it wasn't before. Codex's mechanism is technically valid.Practically, the risk is negligible — so I'm fine leaving it. This is the once-per-mount app-restart handler; the dangerous branch only runs when there's no active trip on launch, and it would require the user to start a brand-new trip during a sub-second startup async window (the continue-trip modal is itself gated behind the splash screen being hidden). Not a realistic sequence.
If you ever want exact parity with the old read-after-cleanup semantics, the minimal change is to read the latest subscribed value from a ref after
await checkAndCleanGpsNotification()instead of the pre-await snapshot — but that's optional and arguably outside this refactor's scope. 👍 to leaving as-is.