You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
React Native Android layout glitches with session recording #3140
Posthog's session recording on Android with React Native causes layout glitches by resetting the safe area to zero. This was reported earlier, but I managed to make a minimal repro. #2155
Run on an Android 15+ device that has some kind of notch or display cutout (I used a Galaxy Fold)
If you are using bun (but any package manager should work):
bun install
bun android
Expected outcome:
SafeAreaInsets.top should not reset to zero
Actual outcome:
It periodically resets to zero, causing the whole UI to jump. See change log text box:
The issue does not happen on iOS or with enableSessionReplay: false.
Related sub-libraries
All of them
posthog-js (web)
posthog-js-lite (web lite)
posthog-node
posthog-react-native
@posthog/react
@posthog/ai
@posthog/convex
@posthog/nextjs-config
@posthog/nuxt
@posthog/rollup-plugin
@posthog/webpack-plugin
Additional context
Thank you for your bug report – we love squashing them!
The PostHog Android SDK's session replay takes screenshots via PixelCopy on every throttled draw. The old code created and destroyed a new HandlerThread for every single screenshot (~1/sec). The PixelCopy callback then
traverses the entire view tree from that background thread to find maskable widgets.
On Android 15+, which enforces edge-to-edge, this thread churn combined with background view-tree access creates a race condition where rootWindowInsets briefly returns zero values. Since react-native-safe-area-context
reads these insets via OnPreDrawListener, the safe area periodically flashes to zero, causing the UI to jump.
This explains why:
Increasing androidDebouncerDelayMs helps (fewer screenshots = less thread churn)
Debouncing useSafeAreaInsets() helps (masks the transient zeros)
Disabling session replay fixes it entirely
It only happens on Android 15+ (edge-to-edge enforcement changed insets dispatch)
The fix (in posthog-android):
Reuse a single HandlerThread for PixelCopy callbacks instead of creating/destroying one per screenshot
Early bail-out checks (isOnDrawnCalled) at the top of generateSnapshot() and findMaskableWidgets() to minimize time spent reading stale view state off the main thread
Reduce allocations during the view tree walk (reusable Rect/Point, Set instead of List for password types, contains(ignoreCase=true) instead of lowercase())
Im not sure if this alone is enough, but might improve things
Given that the issue seems to be diagnosed, should we be expecting a fix? I'm the creator of the original issue reporting this, so I've been more than a year with no Android session replays.
Activity
ablaszkiewicz commentedon Feb 24, 2026
@marandaneto, @ioannisj
marandaneto commentedon Feb 24, 2026
thanks @Nezz will try to reproduce it
marandaneto commentedon Feb 26, 2026
The PostHog Android SDK's session replay takes screenshots via PixelCopy on every throttled draw. The old code created and destroyed a new HandlerThread for every single screenshot (~1/sec). The PixelCopy callback then
traverses the entire view tree from that background thread to find maskable widgets.
On Android 15+, which enforces edge-to-edge, this thread churn combined with background view-tree access creates a race condition where rootWindowInsets briefly returns zero values. Since react-native-safe-area-context
reads these insets via OnPreDrawListener, the safe area periodically flashes to zero, causing the UI to jump.
This explains why:
The fix (in posthog-android):
Im not sure if this alone is enough, but might improve things
Nezz commentedon Mar 10, 2026
I tried
"posthog-react-native-session-replay": "1.5.1"but sadly I don't see a noticeable improvement so for now we can't enable it on Android.joaqo commentedon Mar 27, 2026
Given that the issue seems to be diagnosed, should we be expecting a fix? I'm the creator of the original issue reporting this, so I've been more than a year with no Android session replays.
marandaneto commentedon Apr 29, 2026
there were some improvements on android and ios, please try the latest version and report back if there is still an issue