[MS-1376] Add a guard against a race condition in MatcherFragment#1604
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a navigation-state guard in MatchFragment to prevent delivering a match result after the user has navigated away (e.g., to the exit form), avoiding a crash in the Orchestrator caused by an unexpected result type/order.
Changes:
- Adds a
NavController.currentDestinationcheck before callingfinishWithResult()formatchResponse. - Documents the intent with an inline comment.
| viewModel.matchResponse.observe( | ||
| viewLifecycleOwner, | ||
| LiveDataEventWithContentObserver { | ||
| findNavController().finishWithResult(this, it) | ||
| // Guard against delivering the match result after the fragment has already | ||
| // been popped (e.g. exit form submitted after match finished in the background). | ||
| if (findNavController().currentDestination?.id == R.id.matcherFragment) { | ||
| findNavController().finishWithResult(this, it) | ||
| } |
There was a problem hiding this comment.
LiveDataEventWithContentObserver calls getContentIfNotHandled() before entering this lambda, so when currentDestination is not matcherFragment the match result will be silently consumed (lost). This can leave the user stuck if they navigate to the exit form and then tap “continue/go back” (no submission): when they return to MatchFragment the match has finished but the result event can no longer be delivered. Consider observing the LiveDataEventWithContent directly and only calling getContentIfNotHandled() after verifying the destination (or otherwise buffering the result until the fragment is current again).
bbb0554 to
b729abb
Compare
|



JIRA ticket
Will be released in: 2026.2.0
Root cause analysis (for bugfixes only)
First known affected version: a very old one!?
Notable changes
Testing guidance
Additional work checklist