Guard your Compose UI efficiency. Catch recomposition regressions before your users.
The Problem
Compose's recomposition behavior is an implicit contract — composables should recompose when their inputs change and stay stable otherwise. But that contract breaks silently, and today's options for catching it are limited:
Layout Inspector — manual, requires a running app, can't automate, can't run in CI
Manual tracking code — SideEffect counters, LaunchedEffect logging, wrapper composables; invasive, doesn't scale, and ships in your production code
Neither gives you a testable, automatable contract you can enforce on every PR
What Dejavu Does
Dejavu is a test-only library that turns recomposition behavior into assertions. Tag your composables with standard Modifier.testTag(), write expectations against recomposition counts, and get structured diagnostics when something changes — whether from a teammate, a library upgrade, an AI agent rewriting your UI code, or a refactor that silently destabilizes a lambda.
Zero production code changes — just Modifier.testTag()
One-line test setup — createRecompositionTrackingRule()
Per-instance tracking — multiple instances of the same composable get independent counters
Quick Start
1. Add dependency
DejaVu 0.5.1 requires Android compile SDK 37 and min SDK 24. The release uses
Compose Multiplatform 1.12.0; Android Compose 1.11 remains supported with an enforced BOM.
See Compatibility before adding the dependency to an older Compose project.
Use your enforced Compose BOM for the unversioned Compose test artifacts. See the
complete setup for the runner, compatible
Android test dependencies, and KMP source sets.
Version 0.5.1 moves the Maven group to dev.mttmcknn. Replace the previous
me.mmckenna.dejavu:dejavu dependency with dev.mttmcknn:dejavu:0.5.1; do not add
both artifacts. Kotlin packages and imports remain dejavu.*, and the library's
runtime behavior and public APIs are unchanged from 0.5.0. Earlier releases keep
their original Maven coordinates.
2. Write a test
@get:Rule
val composeTestRule = createRecompositionTrackingRule()
@Test
fun incrementCounter_onlyValueRecomposes() {
composeTestRule.onNodeWithTag("inc_button")
.performClick()
composeTestRule.onNodeWithTag("counter_value")
.assertRecompositions(exactly = 1)
composeTestRule.onNodeWithTag("counter_title")
.assertStable() // stable = zero recompositions
}
This test assumes the counter screen is already set. Use createRecompositionTrackingRule<YourActivity>()
to launch an activity that sets that screen, or call composeTestRule.setContent { YourScreen() }
when using the plain rule. The Getting Started guide
includes a complete example.