-
Notifications
You must be signed in to change notification settings - Fork 82
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
Compose stops recomposing in tests #326
Comments
This checks out. We're discussing this with the compose folks. No clue what's going on yet! |
Another note to drop here: Our current suspicion is that this is caused by
So the workaround for this is just to not use |
Am I under the right assumption that the fix needs to trickle into the Jetbrains Compose runtime before I can verify the fix?
|
Only if you are experiencing it on targets other than Android. If you are only using it on Android, an explicit dependency on the newer version is all you need. |
Yes, JVM unit tests mainly. We haven't seen an issue on Android. |
Yes, alas, we must wait. It's not even merged into their builds yet. |
We came across this issue again and this made me rerun the test and we still see the same problem in unit tests. I cannot tell if the fix for Android mentioned above trickled into Compose Multiplatform. This is my dependency graph for the Android unit tests:
I see the same test failing for the desktop and the iOS Simulator flavor of our KMP project as well. This is with Kotlin 2.0.21, but I don't think 2.1.0 makes a difference in this regard. |
In a weird combination of
StateFlow
,backgroundScope
,UnconfinedTestDispatcher
,collectAsState()
and theImmediate
recomposition mode the Compose runtime stops recomposing and Flows produced by Molecule stop sending events.This test passes:
If I change the initial value to something else such as
collectAsState("abc")
, then only "one" from the StateFlow is emitted but no other value anymore even though the StateFlow value changes. The composable function only recomposes when the initial value of theStateFlow
and thecollectAsState
function are equal. This seems to be the bug.Changing the flow to a
MutableSharedFlow
fixes the issue, because there’s no default value. Removing theUnconfinedTestDispatcher
also fixes the issue. In this case it emits the initial value fromcollectAsState
first, then the default value from theStateFlow
and then all other changes. Using the same initial values also resolves the bug (the problem here is thatStateFlow
is an implementation detail of the underlying API, this example is simplified). It only breaks when the initial values are different.The text was updated successfully, but these errors were encountered: