Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snapshots] Error when snapshotting preview with Dialog #136

Open
rbro112 opened this issue May 16, 2024 · 1 comment
Open

[Snapshots] Error when snapshotting preview with Dialog #136

rbro112 opened this issue May 16, 2024 · 1 comment

Comments

@rbro112
Copy link
Contributor

rbro112 commented May 16, 2024

There's a crash upon snapshotting a preview that contains a dialog. As a minimal repro:

@Preview
@Composable
fun ConfirmationAlertDialogPreview() {
  SnapshotsSampleTheme {
    Box(
      modifier = Modifier
        .fillMaxSize()
        .background(color = MaterialTheme.colorScheme.background)
    ) {
      // Other UI
      ConfirmationAlertDialog(...)
    }
  }
}

@Composable
fun ConfirmationAlertDialog(
  onDismiss: () -> Unit,
  onConfirm: () -> Unit,
  message: String,
  title: String,
  confirmButtonLabel: String,
  confirmButtonColor: Color = Color.Unspecified,
) {
  AlertDialog(
    onDismissRequest = onDismiss,
    confirmButton = { ... },
    dismissButton = { ... },
    title = { Text(title) },
    text = { Text(message) },
  )
}

Running this with ./gradlew emergeLocalSnapshotsDebug results in a crash with the following stacktrace. The same crash occurs when running on Emerge's cloud snapshotting system.

There was 1 failure:
1) MaterialThemedComponentWithDialog_GenSnapshot(com.emergetools.snapshots.sample.ui.MaterialThemedComponentWithDialog_-1316455265_GenSnapshot)
java.lang.AssertionError: Failed to capture a node to bitmap.
Reason: Expected exactly '1' node but found '2' nodes that satisfy: (isRoot)
Nodes found:
1) Node #11 at (l=0.0, t=77.0, r=1080.0, b=2028.0)px
Has 1 child
2) Node #12 at (l=0.0, t=0.0, r=770.0, b=382.0)px
Has 1 child

        at androidx.compose.ui.test.SemanticsNodeInteraction.fetchOneOrDie(SemanticsNodeInteraction.kt:145)
        at androidx.compose.ui.test.SemanticsNodeInteraction.fetchSemanticsNode(SemanticsNodeInteraction.kt:79)
        at androidx.compose.ui.test.AndroidImageHelpers_androidKt.captureToImage(AndroidImageHelpers.android.kt:51)
        at com.emergetools.snapshots.EmergeSnapshots.take(EmergeSnapshots.kt:72)
        at com.emergetools.snapshots.sample.ui.MaterialThemedComponentWithDialog_-1316455265_GenSnapshot.MaterialThemedComponentWithDialog_GenSnapshot(MaterialThemedComponentWithDialog_-1316455265_GenSnapshot.kt:34)
@rbro112 rbro112 changed the title Error when snapshotting preview with Dialog [Snapshots] Error when snapshotting preview with Dialog Aug 28, 2024
@rbro112
Copy link
Contributor Author

rbro112 commented Sep 16, 2024

We're working on a fix for this! For the time being, we'd recommend adding the @IgnoreEmergeSnapshot annotation to any previews that trigger this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant