Skip to content

Commit

Permalink
feat(react-native): loading react-native apps in the background will …
Browse files Browse the repository at this point in the history
…no longer start a session
  • Loading branch information
lemnik committed Jun 6, 2024
1 parent c69e0c6 commit 6af8054
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changed

- (plugin-react) Modified the polynomial regular expression to remove the ambiguity [#2135](https://github.com/bugsnag/bugsnag-js/pull/2135)
- (react-native) ReactNative apps loaded in the background will no longer start a new session [#2154](https://github.com/bugsnag/bugsnag-js/pull/2154)

## [7.23.0] - 2024-05-09

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ void resumeSession() {
}
}

void resumeSessionOnStartup() {
try {
Client client = Bugsnag.getClient();
if (Boolean.TRUE.equals(client.sessionTracker.isInForeground())) {
plugin.resumeSession();
}
} catch (Throwable exc) {
logFailure("resumeSessionOnStartup", exc);
}
}

void updateContext(@Nullable String context) {
try {
plugin.updateContext(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void resumeSession() {
impl.resumeSession();
}

@Override
public void resumeSessionOnStartup() {
impl.resumeSessionOnStartup();
}

@Override
public void updateContext(@Nullable String context) {
impl.updateContext(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ void resumeSession() {
impl.resumeSession();
}

@ReactMethod
public void resumeSessionOnStartup() {
impl.resumeSessionOnStartup();
}

@ReactMethod
void updateContext(@Nullable String context) {
impl.updateContext(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- (void)startSession;
- (void)pauseSession;
- (void)resumeSession;
- (void)resumeSessionOnStartup;

- (void)addFeatureFlags:(NSArray *)readableArray;
- (void)addFeatureFlag:(NSString *)name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ @implementation BugsnagReactNative
[Bugsnag resumeSession];
}

RCT_EXPORT_METHOD(resumeSessionOnStartup) {
[Bugsnag resumeSession];
}

RCT_EXPORT_METHOD(addFeatureFlags:(NSArray *)readableArray) {
NSMutableArray *array = [NSMutableArray new];
if(readableArray == nil) {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/src/NativeBugsnag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface Spec extends TurboModule {

resumeSession(): void

resumeSessionOnStartup(): void

updateContext(context: string | undefined | null): void

addMetadata(section: string, metadata?: UnsafeObject): void
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const _createClient = (opts, jsOpts) => {
NativeClient.updateCodeBundleId(opts.codeBundleId)
}

if (bugsnag._config.autoTrackSessions) bugsnag.resumeSession()
if (bugsnag._config.autoTrackSessions) NativeClient.resumeSessionOnStartup()

bugsnag._logger.debug('Loaded!')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jest.mock('react-native', () => {
_events: events,
_clear: () => { while (events.length) events.pop() },
resumeSession: () => {},
resumeSessionOnStartup: () => {},
pauseSession: () => {},
startSession: () => {}
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jest.mock('react-native', () => ({
})),
updateCodeBundleId: jest.fn(),
resumeSession: jest.fn(),
resumeSessionOnStartup: jest.fn(),
addFeatureFlags: jest.fn(),
leaveBreadcrumb: jest.fn(),
getPayloadInfo: jest.fn().mockReturnValue({}),
Expand Down

0 comments on commit 6af8054

Please sign in to comment.