Fixed
Status Update
Comments
il...@google.com <il...@google.com>
mg...@google.com <mg...@google.com>
ap...@google.com <ap...@google.com> #2
Yigit, do you have time to fix it?
reemission of the same liveData is racy
reemission of the same liveData is racy
il...@google.com <il...@google.com>
pr...@google.com <pr...@google.com> #3
yea i'll take it.
he...@reaktor.com <he...@reaktor.com> #4
Thanks for the detailed analysis. This may not be an issue anymore since we've started using Main.immediate there but I' not sure; I'll try to create a test case.
il...@google.com <il...@google.com> #5
just emitting same live data reproduces the issue.
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
ha...@gmail.com <ha...@gmail.com> #6
With 2.2.0-alpha04 (that use Main.immediate), the issue seems to be still there (I tested it by calling emitSource() twice, like your test case)
Description
When using Compose navigation, calls to navigate should be guarded by lifecycle state to prevent invoking navigation methods while composable is transitioning as an effect of navigation. Given navigation destination:
navigation calls should be guarded by
backStackEntry
lifecycle state to prevent invoking navigation from composable that's under transition:It would be really useful to have a set of lifecycle aware function wrappers for guarding execution of calls, for example:
or standalone composable version which will use
LocalLifecycleOwner
to access lifecycle state: