Is `SharedTransitionLayout` currently not usable w...
# compose-desktop
m
Is
SharedTransitionLayout
currently not usable with
LazyColumn
? After putting much work getting the animations to work perfectly, the
LazyColumn
now often crashes when scrolled. https://issuetracker.google.com/issues/336140982 Bug is marked as fixed, but that version of Compose is not released for Desktop use, and someone already commented it isn't fixed anyway.
d
Are you using LazyColumn or LazyGrid?
m
Both, the shared transition switches between the two. But the crash happens in the LazyColumn. Even if I only leave the LazyColumn in, and remove the shared element transition on the children, it still crashes when scrolling, just because the LazyColumn is inside a SharedTransitionLayout.
All right, the crash only happens if you use
movableContentOf
in the children of the
LazyColumn
that is in a
SharedTransitionLayout
. I removed
movableContentOf
from my list items and the crashing is gone.
d
If you could provide a minimal repro with the
movableContentOf
and
LazyColumn
combo, and steps to trigger crash, I can help verify if the fix from the issue above fixes this crash using 1.8.0-alpha01.
Also note, the issue with LazyColumn should be fixed per confirmation from dev. The crash in LazyGrids is due to incomplete support for lookahead, which we're currently prioritizing addressing
m
@Doris Liu I managed to create a minimal repro. It crashes quickly without user interaction.
Copy code
@OptIn(ExperimentalSharedTransitionApi::class)
fun main() {
    singleWindowApplication {
        var items by remember { mutableStateOf(List(500) { it }) }

        LaunchedEffect(Unit) {
            while (true) {
                delay(10)
                items = items.shuffled()
            }
        }

        SharedTransitionLayout {
            LazyColumn {
                items(items, key = { it }) {
                    val movableContent = remember { movableContentOf { Text("Item $it") } }
                    Box(Modifier.animateItem()) {
                        Box {
                            movableContent()
                        }
                    }
                }
            }
        }
    }
}
d
Thank you. Could you also share the stack trace? I'm seeing a different crash:
java.lang.IllegalArgumentException: measure is called on a deactivated node
as I tried it out locally.
m
Copy code
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Error: Placement happened before lookahead.
	at androidx.compose.ui.internal.InlineClassHelperKt.throwIllegalStateException(InlineClassHelper.kt:26)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.placeSelf-MLgxB_4(LayoutNodeLayoutDelegate.kt:2105)
	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.placeAt-f8xVGno(LayoutNodeLayoutDelegate.kt:767)
	at androidx.compose.ui.layout.Placeable.access$placeAt-f8xVGno(Placeable.kt:35)
	at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50(Placeable.kt:621)
	at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50$default(Placeable.kt:259)
d
This is what I see:
Copy code
Process: androidx.compose.animation.demos.test, PID: 32685
                                                                                                    java.lang.IllegalArgumentException: measure is called on a deactivated node
                                                                                                    	at androidx.compose.ui.internal.InlineClassHelperKt.throwIllegalArgumentException(InlineClassHelper.kt:34)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:2071)
                                                                                                    	at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:668)
                                                                                                    	at androidx.compose.foundation.lazy.layout.LazyLayoutMeasureScopeImpl.measure-0kLqBqw(LazyLayoutMeasureScope.kt:125)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListMeasuredItemProvider.getAndMeasure-0kLqBqw(LazyListMeasuredItemProvider.kt:55)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListMeasuredItemProvider.getAndMeasure--hBUhpc(LazyListMeasuredItemProvider.kt:43)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListMeasuredItemProvider.getAndMeasure--hBUhpc(LazyListMeasuredItemProvider.kt:28)
                                                                                                    	at androidx.compose.foundation.lazy.layout.LazyLayoutItemAnimator.onMeasured(LazyLayoutItemAnimator.kt:255)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListMeasureKt.measureLazyList-LCrQqZ4(LazyListMeasure.kt:366)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke-0kLqBqw(LazyList.kt:350)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke(LazyList.kt:198)
                                                                                                    	at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$1$2$1.invoke-0kLqBqw(LazyLayout.kt:78)
                                                                                                    	at androidx.compose.foundation.lazy.layout.LazyLayoutKt$LazyLayout$1$2$1.invoke(LazyLayout.kt:76)
                                                                                                    	at androidx.compose.ui.layout.LayoutNodeSubcompositionsState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:730)
                                                                                                    	at androidx.compose.ui.node.InnerNodeCoordinator.measure-BRTryo0(InnerNodeCoordinator.kt:127)
m
Possibly you are on a different version, and it's fixed on yours but not completely and crashes somewhere else?
I'm on
1.7.0-beta02
now of JetBrains Compose
d
I'm trying it on 1.8.0-alpha01 androidx compose, which contains the fix of the issue that you linked
I reduced your repro snippet further. Some initial investigation has revealed that there is some inconsistency between what node SubcomposeLayout considers ready to be reused and what was actually deactivated. Will need more investigation to figure out what's causing that. Until then, you could track it at: https://issuetracker.google.com/368429360
m
Thank you. 👍 Though now I wonder why removing
movableContentOf
from my application fixed the crashing, if it isn't what triggers this issue after all.
Small update: removing
movableContentOf
only apparently resolved this issue for me. Although it doesn't crash almost immediately now, it still crashes – just very rarely. I'm removing the
SharedTransitionLayout
for now and hopefully I can add it back at some point.
d
That's unfortunate. 😞 Good news is your repro helped us narrow down two issues in two different components, and the fixes are in review. Once they are released, you should be able to get back to using shared elements.
👍 1
m
@Doris Liu I have now updated to Compose Multiplatform 1.7.3, which is based on Foundation 1.7.6. The issue tracker says the fix is in foundation:1.7.4, so my understanding is that I should have the fix now. But my reproducer above still crashes – it just takes a minute or two of letting it run now, instead of crashing almost immediately. Is there more to this issue?
For anyone finding this, I commented under the issue that it's still happening: https://issuetracker.google.com/issues/368429360#comment34
d
Thanks for the update. We found other code paths that led to the same issue, and landed the fix in 1.8. Please see: https://issuetracker.google.com/336140982
m
Thank you, can confirm it's fixed in
org.jetbrains.compose:1.8.0-alpha03
, which uses
1.8.0-beta01
of Jetpack Compose.
👍 1
381 Views