-
Notifications
You must be signed in to change notification settings - Fork 58
fix(session-replay-react-native): prevent interacting with the view hierarchy from a background thread #1425
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,9 @@ class PluginSessionReplayReactNative: NSObject { | |||||||||
| serverZone: serverZone == "EU" ? .EU : .US, | ||||||||||
| enableRemoteConfig: enableRemoteConfig) | ||||||||||
| if (autoStart) { | ||||||||||
| sessionReplay.start() | ||||||||||
| DispatchQueue.main.async { | ||||||||||
| self.sessionReplay.start() | ||||||||||
| } | ||||||||||
| } | ||||||||||
| resolve(nil) | ||||||||||
| } | ||||||||||
|
|
@@ -65,15 +67,19 @@ class PluginSessionReplayReactNative: NSObject { | |||||||||
| @objc(start:reject:) | ||||||||||
| func start(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void { | ||||||||||
| print("start") | ||||||||||
| sessionReplay.start() | ||||||||||
| resolve(nil) | ||||||||||
| DispatchQueue.main.async { | ||||||||||
| self.sessionReplay.start() | ||||||||||
| resolve(nil) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| @objc(stop:reject:) | ||||||||||
| func stop(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void { | ||||||||||
| print("stop") | ||||||||||
| sessionReplay.stop() | ||||||||||
| resolve(nil) | ||||||||||
| DispatchQueue.main.async { | ||||||||||
| self.sessionReplay.stop() | ||||||||||
| resolve(nil) | ||||||||||
| } | ||||||||||
|
Comment on lines
+79
to
+82
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| @objc(flush:reject:) | ||||||||||
|
|
@@ -86,7 +92,9 @@ class PluginSessionReplayReactNative: NSObject { | |||||||||
| @objc(teardown:reject:) | ||||||||||
| func teardown(_ resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) -> Void { | ||||||||||
| print("teardown") | ||||||||||
| sessionReplay.stop() | ||||||||||
| resolve(nil) | ||||||||||
| DispatchQueue.main.async { | ||||||||||
| self.sessionReplay.stop() | ||||||||||
| resolve(nil) | ||||||||||
| } | ||||||||||
|
Comment on lines
+97
to
+98
|
||||||||||
| resolve(nil) | |
| } | |
| } | |
| resolve(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent promise resolution pattern: In this method,
resolve(nil)is called inside theDispatchQueue.main.asyncblock (line 72), but in thesetup()method whenautoStartis true (lines 41-43), theresolve(nil)is called outside the async block (line 45).For consistency, either:
resolve(nil)outside the async block here to matchsetup()(resolves immediately, fire-and-forget pattern)resolve(nil)insetup()inside its async block (waits for completion)The choice depends on whether JavaScript callers need to wait for the operation to complete on the main thread before the promise resolves.