The code below describes an OrdersFragment screen that shows the number of active orders and the last event text from ViewModel. After a recent PR, the screen started behaving unstably when leaving the page and returning back.
You need to review the changes and find defects in the regression.
uiState only while the fragment View is at least in the STARTED state.View is destroyed, updates must no longer access the old binding.Emit update several times.Rotate or navigate away from the page and come back.Emit update again.You can use this scenario in the app:
Open Orders screen
Tap "Emit update"
Rotate device
Tap "Emit update" again
activeCount and lastEvent are updated synchronously.View is recreated, the old screen instance does not receive updates.View.androidx.fragment:fragment-ktx:1.8.2androidx.lifecycle:lifecycle-runtime-ktx:2.8.4androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1Fragment + XML View Binding, without ComposeOrdersViewModel survives fragment View recreation, and emitUpdate() can be triggered by a button in the current ViewUse line comments to explain the problem, its impact, the fix and how to test it.