Skip to content

feat(session-replay-react-native): add teardown and runtime opt-out - #1951

Merged
aliaksandr-kazarez merged 8 commits into
mainfrom
sdkrn-62-add-teardown-setoptout
Aug 25, 2026
Merged

feat(session-replay-react-native): add teardown and runtime opt-out#1951
aliaksandr-kazarez merged 8 commits into
mainfrom
sdkrn-62-add-teardown-setoptout

Conversation

@aliaksandr-kazarez

@aliaksandr-kazarez aliaksandr-kazarez commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add public teardown() and runtime setOptOut(boolean) APIs across JavaScript, TurboModule, iOS, and Android
  • clear lifecycle state during teardown so the SDK can be initialized again
  • make Amplitude and Segment plugin teardown paths shut down the native SDK, and expose runtime opt-out controls

SDKRN-62

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

Test plan

  • Build @amplitude/session-replay-react-native and @amplitude/segment-session-replay-plugin-react-native
  • Lint both packages
  • Standalone tests: 56 passed
  • Segment tests: 19 passed

Native example compilation was not completed because the example Gradle setup requires a Yarn-hoisted React Native Gradle plugin, while this worktree's package-manager metadata blocks that Yarn install; package builds, type generation, lint, and unit tests pass.


Posted automatically with Cursor. LLMs make mistakes — please verify before acting.


Note

Medium Risk
Touches privacy-sensitive opt-out and native lifecycle teardown/re-init across platforms; Android’s reboot-on-opt-out path is non-trivial and could affect recording state if mis-timed.

Overview
Adds setOptOut(boolean) and teardown() end-to-end (JS public API, TurboModule spec, iOS, Android) so apps can disable replay collection at runtime and fully shut down the native SDK. teardown() resets JS module state (isInitialized, logger) so init() can run again; plugin teardown() paths now call native teardown() instead of only stop().

The Amplitude SessionReplayPlugin forwards config.optOut into native setup and implements onOptOutChanged so client.setOptOut() updates replay. The Segment plugin’s shutdown() uses teardown() and exposes setOptOut.

On Android, opt-out is implemented by persisting bridge config and rebooting the native instance (skip construction while opted out; recreate on opt-in, respecting shouldStart). On iOS, runtime opt-out sets the native optOut property. The example app adds manual buttons for the new APIs.

Reviewed by Cursor Bugbot for commit 3e698ce. Bugbot is set up for automated code reviews on this repo. Configure here.

aliaksandr-kazarez and others added 3 commits August 21, 2026 13:11
Remove autoStart and replay-property stamping. Standalone consumers now initialize first and
explicitly start recording.

BREAKING CHANGE: SessionReplayConfig.autoStart and getSessionReplayProperties() are removed.
Events are no longer stamped with session replay properties.
…onfigure

The standalone SDK no longer auto-starts, so adding this plugin left
recording off. Restore the previous behavior with a plugin-owned
`autoStart` option (default true) that calls `start()` after `init()`.

`autoStart` is stripped before `init()` so it is not forwarded across the
native bridge, and the README no longer claims the plugin enriches events.

Co-authored-by: Cursor <cursoragent@cursor.com>
@linear-code

linear-code Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

SDKRN-62

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 61.58 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 134.97 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 215.62 KB (0%)
@amplitude/element-selector (gzipped esm) 2.67 KB (0%)

…ted out

session-replay-android still has no runtime opt-out setter. Instead of
rebuilding a constructor-opted-out instance, keep JS/native config and
do not construct SessionReplay until opt-out is false.
Base automatically changed from sdkrn-63-remove-autostart-getsessionreplayproperties to main August 22, 2026 00:27
Keep Android recording intent as shouldStart, reconstruct the native
instance when opt-out changes, and drop unused JS fullConfig after init.
@aliaksandr-kazarez
aliaksandr-kazarez marked this pull request as ready for review August 22, 2026 01:17
@aliaksandr-kazarez
aliaksandr-kazarez requested a review from a team as a code owner August 22, 2026 01:17
Comment thread packages/session-replay-react-native/src/plugin-session-replay.ts
Comment thread packages/session-replay-react-native/ios/NativeSessionReplay.swift
…OS setOptOut

Wire the plugin to the analytics timeline onOptOutChanged hook, pass
config.optOut into native setup, and avoid force-unwrapping after teardown.
Comment thread packages/session-replay-react-native/ios/NativeSessionReplay.swift
…rdown safe

Create the next Android SessionReplay instance before shutting down the
current one, and make remaining iOS bridge methods nil-safe after teardown.
@aliaksandr-kazarez

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.

Reviewed by Cursor Bugbot for commit 3e698ce. Configure here.

Comment thread packages/session-replay-react-native/ios/NativeSessionReplay.swift
@aliaksandr-kazarez
aliaksandr-kazarez merged commit f831aba into main Aug 25, 2026
22 checks passed
@aliaksandr-kazarez
aliaksandr-kazarez deleted the sdkrn-62-add-teardown-setoptout branch August 25, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants