Skip to content

Incorrect preview snapshot sizes #719

@smuldr

Description

@smuldr

The recent 1.46.x and 1.47.x releases have broken something in the way snapshot sizes are determined. It seems to be related to the heightDp and widthDp attributes in the Preview annotations.

Context

We are using Roborazzi together with the ComposablePreviewScanner to automatically generate snapshots for our previews. Basically we use the scanner to get a list of all the previews and then use a big for loop to capture and assert all the preview snapshots.

Problem

Some of our components have previews where we fix the height of the preview to check the UI in very small or very tall screens. This was working fine with Roborazzi release verion 1.45.0, but in the latest releases these previews also change the size of other snapshots.

@Preview
@Composable
fun MyComponent_Preview1() {
     Text("default size")
}

// Smaller preview results in a smaller snapshot.
@Preview(heightDp = 600)
@Composable
fun MyComponent_Preview2() {
    Text("small size")
}

// This preview should have a snapshot with default size but it is only 600dp high!
@Preview
@Composable
fun MyComponent_Preview3() {
    Text("default size again")
}

So it feels like that if one preview fixes the height at 600dp then the following previews also gets 600dp height, even if they have no heightDp attribute.

How to reproduce

I created a minimal reproduction project here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions