Wait for idle sync before capturing screenshot#86
Draft
EmilioBejasa wants to merge 4 commits intomainfrom
Draft
Conversation
After JS calls notifyStoryReady() (end of useEffect), Fabric may still have pending layout and mount work queued on the main thread. Taking the screenshot immediately could capture a partially-rendered frame. waitForIdleSync() drains the main thread's Looper before snap() runs, ensuring all native view updates are applied first. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fabric posts a second round of layout/mount work (e.g. Switch thumb animation, text measurement) in response to the first commit, which races with a single waitForIdleSync(). A second call catches that. Also make awaitStoryReady() throw on timeout instead of silently proceeding, so a story that never calls notifyStoryReady() fails loudly rather than capturing a partial screenshot. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2 rounds was still not enough for SwitchCompat: mount → setChecked → animation setup → layout measurement spans several async dispatch cycles in Fabric. 5 rounds covers the full chain empirically. Made the count overridable via getIdleSyncRounds() for consumers who need to tune it for their own native components. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
waitForIdleSync() only drains the Looper. Fabric's mount phase is scheduled as a ReactChoreographer FrameCallback (VSYNC-driven), so it was invisible to waitForIdleSync() — the screenshot was taken before native views were actually updated. Fix 1: replace waitForIdleSync() loops with awaitChoreographerFrames(), which posts a FrameCallback and blocks until it fires, then drains the Looper for any follow-up Looper work in each frame. Fix 2: disable system animation scales via UiAutomation before the test run so SwitchCompat's thumb animation (and similar) can't render in an intermediate state at snapshot time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After JS calls
notifyStoryReady()(at the end of auseEffect), Fabric may still have pending layout and mount work queued on the main thread. Taking the screenshot immediately after the latch releases can capture a partially-rendered frame, causing flaky diffs in Screenshotbot.waitForIdleSync()drains the main thread'sLooperbeforeScreenshot.snap()runs, ensuring all native view updates from the Fabric commit are applied first.The race condition
After this fix:
🤖 Generated with Claude Code