Skip to content

Track recomposition triggered by changing of state value inside Composable functionΒ #89

@xiaozhikang0916

Description

@xiaozhikang0916

Here is a simple code that has a chaning state inside a composable function, which triggering the whole function recomposing.

@TraceRecomposition(tag = "State")
@Composable
fun RecompositionState(tag: String) {
  var state by remember {
    mutableIntStateOf(0)
  }
  LaunchedEffect(Unit) {
    while(true) {
      state += 1
      delay(1.seconds)
    }
  }
  Text(text = "tag $state")
}

Currently, @TraceRecomposition only reports that this function is recomposing and the parameter tag is stable:

[Recomposition #3] RecompositionState (tag: State)
  └─ tag: kotlin.String stable (state)
[Recomposition #4] RecompositionState (tag: State)
  └─ tag: kotlin.String stable (state)
[Recomposition #5] RecompositionState (tag: State)
  └─ tag: kotlin.String stable (state)
[Recomposition #6] RecompositionState (tag: State)
  └─ tag: kotlin.String stable (state)

It would be nice if it can print out that it is changing of state that triggering the recomposition.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions