Example preview test that causes record to hang - #814
Conversation
I've added an example Preview function containing a dialog and text with inline content that causes roborazzi's record to hang. Just to confirm: the IDE preview window does render a preview.
📝 WalkthroughWalkthroughAdded a new preview composable for testing inline content in Material3 BasicAlertDialog with AnnotatedString and icon placeholders. Reformatted an existing preview function's modifier expression to multiline style. Added supporting string resources for preview tests. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt`:
- Around line 550-583: The PreviewTextWithInlineContent composable hangs during
recording because InlineTextContent triggers animated timing; add the
Robolectric preview annotation to disable auto-advance by annotating the
PreviewTextWithInlineContent function with
`@RoboComposePreviewOptions`(manualClockOptions = [ManualClockOptions()]) (ensure
the annotation is placed alongside `@OptIn` and `@Preview` and import
ManualClockOptions/RoboComposePreviewOptions if missing) so the preview uses a
manual clock and won't hang during recording.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d87a86c7-23ed-4ee6-ba5f-8f696c1438de
📒 Files selected for processing (2)
sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.ktsample-generate-preview-tests/src/main/res/values/strings.xml
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Preview | ||
| @Composable | ||
| fun PreviewTextWithInlineContent() { | ||
| BasicAlertDialog(onDismissRequest = {}) { | ||
|
|
||
| val text = buildAnnotatedString { | ||
| append(stringResource(R.string.testing_inline_content)) | ||
| append(" ") | ||
| appendInlineContent("linkIcon", "[linkIcon]") | ||
| append(" ") | ||
| append(stringResource(R.string.for_preview_tests)) | ||
| } | ||
|
|
||
| Text( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| text = text, | ||
| style = MaterialTheme.typography.bodySmall, | ||
| textAlign = TextAlign.Center, | ||
| inlineContent = mapOf( | ||
| "linkIcon" to InlineTextContent( | ||
| placeholder = Placeholder(20.sp, 20.sp, PlaceholderVerticalAlign.Center), | ||
| children = { | ||
| Icon( | ||
| modifier = Modifier.fillMaxSize(), | ||
| imageVector = Icons.Default.Add, | ||
| contentDescription = null, | ||
| ) | ||
| }, | ||
| ), | ||
| ), | ||
| ) | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Inspect available options on RoboComposePreviewOptions to find exclusion/gating knobs.
rg -n --type=kt -C4 'annotation class RoboComposePreviewOptions|class RoboComposePreviewOptions'
# 2) Inspect current usages to mirror an existing exclusion pattern (if any).
rg -n --type=kt -C3 '@RoboComposePreviewOptions|RoboComposePreviewOptions\('
# 3) Confirm this new preview currently has no gating annotation besides `@Preview`.
rg -n --type=kt -C3 'fun PreviewTextWithInlineContent|@Preview|@OptIn\(ExperimentalMaterial3Api::class\)'Repository: takahirom/roborazzi
Length of output: 89
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Find RoboComposePreviewOptions definition
echo "=== Searching for RoboComposePreviewOptions definition ==="
rg -n 'annotation class RoboComposePreviewOptions|class RoboComposePreviewOptions' -A 10
# 2) Find usages of RoboComposePreviewOptions
echo -e "\n=== Searching for RoboComposePreviewOptions usages ==="
rg -n '@RoboComposePreviewOptions|RoboComposePreviewOptions(' -B 2 -A 2
# 3) Verify current annotations on PreviewTextWithInlineContent
echo -e "\n=== Current annotations on PreviewTextWithInlineContent ==="
rg -n 'fun PreviewTextWithInlineContent' -B 5
# 4) Check if there are any exclusion/recording-related annotations in the codebase
echo -e "\n=== Searching for exclusion or recording-related patterns ==="
rg -n 'record|exclude|skipRecord|Recorder' -i --max-count=20Repository: takahirom/roborazzi
Length of output: 1905
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Get full RoboComposePreviewOptions.kt definition
echo "=== Full RoboComposePreviewOptions definition ==="
cat roborazzi-annotations/src/main/java/com/github/takahirom/roborazzi/annotations/RoboComposePreviewOptions.kt
# 2) Find usages (with escaped parenthesis)
echo -e "\n=== Searching for `@RoboComposePreviewOptions` usages ==="
rg -n '@RoboComposePreviewOptions' -B 2 -A 5
# 3) Verify PreviewTextWithInlineContent annotations
echo -e "\n=== Current annotations on PreviewTextWithInlineContent ==="
rg -n 'PreviewTextWithInlineContent' -B 10
# 4) Look for any skip/exclude recording patterns
echo -e "\n=== Searching for recording exclusion patterns ==="
rg -n 'skipRecord|excludeRecord|skip.*[Rr]ecord|exclude.*[Rr]ecord'Repository: takahirom/roborazzi
Length of output: 4890
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) Check README and docs for recording exclusion guidance
echo "=== Searching docs for recording/exclusion guidance ==="
rg -n 'record|exclude|skip' README.md docs/ -i -B 2 -A 2 | head -80
# 2) Look for PR context or TODO comments about hanging previews
echo -e "\n=== Searching for hanging/issue context ==="
rg -n 'hang|inline.*content|deadlock' -i -B 2 -A 2 | head -50
# 3) Check the PR or related files to understand the PR objective
echo -e "\n=== Searching for PR context or objectives ==="
rg -n 'record.*hang|hang.*record|inline.*content.*hang' -i
# 4) List other preview annotations/patterns to find alternative gating
echo -e "\n=== Other `@Preview` patterns in test file ==="
rg -n '@Preview' sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt -B 3 | head -60Repository: takahirom/roborazzi
Length of output: 11209
🏁 Script executed:
#!/bin/bash
set -euso pipefail
# 1) Search for issue `#768` mentions or comments
echo "=== Searching for issue 768 context ==="
rg -n '768|inline.*content.*hang|hang.*preview' -i
# 2) Look for TODO or FIXME about skipping/excluding previews
echo -e "\n=== Looking for TODOs about recording exclusion ==="
rg -n 'TODO|FIXME' -B 1 -A 1 | grep -i -E 'skip|record|exclude|preview|inline|hang' -A 2 -B 2
# 3) Search for any configuration or annotation that might control recording
echo -e "\n=== Searching for skip/ignore patterns ==="
rg -n 'ignore|skip|exclude' -i -A 2 | head -60
# 4) Check if there's a way to exclude tests from running
echo -e "\n=== Searching for test exclusion patterns ==="
rg -n '@Ignore|Ignore\(|skip.*=.*true' -i -B 1 -A 1Repository: takahirom/roborazzi
Length of output: 8625
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Check the RoborazziPreviewScannerSupport.kt file around issue 768 reference
echo "=== RoborazziPreviewScannerSupport.kt around issue 768 ==="
rg -n 'See.*768' roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt -B 10 -A 10
# Also check if there's a mechanism to filter/exclude previews
echo -e "\n=== Preview filtering logic ==="
rg -n 'filter|exclude|skip' roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.kt -B 2 -A 2
# Check the full file to understand the structure
echo -e "\n=== File structure ==="
wc -l roborazzi-compose-preview-scanner-support/src/main/java/com/github/takahirom/roborazzi/RoborazziPreviewScannerSupport.ktRepository: takahirom/roborazzi
Length of output: 1788
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Check how ManualClockOptions is used and when it disables autoAdvance
echo "=== How manualClockOptions affects autoAdvance ==="
rg -n 'autoAdvance|manualClockOptions' roborazzi-compose-preview-scanner-support/src/main/java/ -B 3 -A 3
# Check the actual implementation in the test rule
echo -e "\n=== Looking for composeTestRule implementation ==="
rg -n 'class.*ComposeTestRule|mainClock.*autoAdvance' -B 2 -A 2 | head -60
# Verify what happens when manualClockOptions is empty vs populated
echo -e "\n=== PreviewWithEmptyOptions to see if it needs special handling ==="
rg -n 'PreviewWithEmptyOptions' -A 8Repository: takahirom/roborazzi
Length of output: 12643
Add @RoboComposePreviewOptions to prevent hanging during recording.
This preview uses InlineTextContent with animations that can cause recording to hang (issue #768). Gate it with @RoboComposePreviewOptions(manualClockOptions = [ManualClockOptions()]) to disable auto-advance timing, matching the pattern used in PreviewWithEmptyOptions:
Applied change
`@OptIn`(ExperimentalMaterial3Api::class)
`@RoboComposePreviewOptions`(manualClockOptions = [ManualClockOptions()])
`@Preview`
`@Composable`
fun PreviewTextWithInlineContent() {
// ... rest of implementation
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@sample-generate-preview-tests/src/main/java/com/github/takahirom/preview/tests/Previews.kt`
around lines 550 - 583, The PreviewTextWithInlineContent composable hangs during
recording because InlineTextContent triggers animated timing; add the
Robolectric preview annotation to disable auto-advance by annotating the
PreviewTextWithInlineContent function with
`@RoboComposePreviewOptions`(manualClockOptions = [ManualClockOptions()]) (ensure
the annotation is placed alongside `@OptIn` and `@Preview` and import
ManualClockOptions/RoboComposePreviewOptions if missing) so the preview uses a
manual clock and won't hang during recording.
Summary by CodeRabbit
New Features
Style
Chores