You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that if molecule composition happens together with ui composition the molecule composition is "missed".
It never happens with the ContextClock mode but it's quite easy to reproduce with the Immediate mode and non-ui dispatcher.
Below there is an example of counter that updates the local state and sends a message to update the state produced by molecule. In 5-15 clicks (no need to click fast though) it's possible to get the wrong state when the states are not equal. The next click after that usually makes them equal again (which I think means that the state in molecule gets updated, but it doesn't trigger a recomposition, probably because the ui recomposition is currently in progress).
classMainActivity : ComponentActivity() {
overridefunonCreate(savedInstanceState:Bundle?) {
super.onCreate(savedInstanceState)
val messages =MutableSharedFlow<Unit>(extraBufferCapacity =10)
val state = lifecycleScope.launchMolecule(RecompositionMode.Immediate, Dispatchers.Default) {
var count by remember { mutableIntStateOf(0) }
LaunchedEffect(Unit) {
messages.collect { count++ }
}
count
}
setContent {
val count by state.collectAsState()
var countLocal by remember { mutableIntStateOf(0) }
Column(modifier =Modifier.background(Color.Black)) {
Text(text ="Count: $count", color =Color.White)
Text(text ="Count local: $countLocal", color =Color.White)
Text(
text ="Click me",
color =Color.White,
modifier =Modifier
.clickable {
countLocal++
messages.tryEmit(Unit)
}
)
}
}
}
}
The text was updated successfully, but these errors were encountered:
j2esu
changed the title
RecompositionMode.Immediate with non-ui dispatcher can cause "skipped" recompositions
RecompositionMode.Immediate with non-ui dispatcher can cause "missed" recompositions
Apr 9, 2024
I've noticed that if molecule composition happens together with ui composition the molecule composition is "missed".
It never happens with the ContextClock mode but it's quite easy to reproduce with the Immediate mode and non-ui dispatcher.
Below there is an example of counter that updates the local state and sends a message to update the state produced by molecule. In 5-15 clicks (no need to click fast though) it's possible to get the wrong state when the states are not equal. The next click after that usually makes them equal again (which I think means that the state in molecule gets updated, but it doesn't trigger a recomposition, probably because the ui recomposition is currently in progress).
Molecule 1.4.2
Compose compiler 1.5.11
Compose runtime 1.7.0-alpha06 (to get #396 fixed)
Android SDK 34
The text was updated successfully, but these errors were encountered: