Experiencing a crash with `LazyVerticalGrid`. More...
# compose
a
Experiencing a crash with
LazyVerticalGrid
. More in 🧵
Here is the repro code
Copy code
@Composable
internal fun Test() {
    var isGrid by remember { mutableStateOf(true) }
    val items = remember { (1..200).toList().toMutableStateList() }
    Scaffold(
        topBar = {
            Column {
                Button(onClick = { isGrid = true }) {
                    Text("Grid")
                }
                Button(onClick = { isGrid = false }) {
                    Text("Row")
                }
            }
        },
        modifier = Modifier.statusBarsPadding(),
    ) { paddingValues ->
        LazyVerticalGrid(
            columns = GridCells.Fixed(2),
            modifier = Modifier.padding(paddingValues)
        ) {
            items(
                items = items,
                key = { it.toString() },
                span = {
                    if (isGrid) GridItemSpan(1) else GridItemSpan(2)
                }
            ) { index ->
                if (isGrid) {
                    Item(index)
                } else {
                    Item(index)
                }
            }
        }
    }
}
When you switch to Row, it works fine. Switching back to grid causes a crash.
Copy code
java.lang.IllegalStateException: Place was called on a node which was placed already
As I am not sure if this is a
bug
or my assumption is wrong that I can dynamically update
GridSpans
I am on
2025.02.00
To reproduce, scroll and toggle between the states.
z
If for some reason updating grid spans is not supported (that would seem weird to me), it definitely shouldn’t crash with this error if you try to do so. Please file a bug.
a