Skip to content
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

Do not ignore require cycle logs for RN >= 0.70 #4214

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

## Unreleased

### Fixes

- Skips ignoring require cycle logs for RN > 0.70 ([#4214](https://github.com/getsentry/sentry-react-native/pull/4214))
antonis marked this conversation as resolved.
Show resolved Hide resolved

### Dependencies

- Bump JavaScript SDK from v8.34.0 to v8.35.0 ([#4196](https://github.com/getsentry/sentry-react-native/pull/4196))
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { MOBILE_REPLAY_INTEGRATION_NAME } from './replay/mobilereplay';
import { createUserFeedbackEnvelope, items } from './utils/envelope';
import { ignoreRequireCycleLogs } from './utils/ignorerequirecyclelogs';
import { mergeOutcomes } from './utils/outcome';
import { ReactNativeLibraries } from './utils/rnlibraries';
import { NATIVE } from './wrapper';

/**
Expand All @@ -37,7 +38,7 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
* @param options Configuration options for this SDK.
*/
public constructor(options: ReactNativeClientOptions) {
ignoreRequireCycleLogs();
ignoreRequireCycleLogs(ReactNativeLibraries.ReactNativeVersion?.version);
options._metadata = options._metadata || {};
options._metadata.sdk = options._metadata.sdk || defaultSdkInfo;
// We default this to true, as it is the safer scenario
Expand Down
13 changes: 11 additions & 2 deletions packages/core/src/js/utils/ignorerequirecyclelogs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { LogBox } from 'react-native';

interface ReactNativeVersion {
major: number;
minor: number;
}

/**
* This is a workaround for using fetch on RN, this is a known issue in react-native and only generates a warning.
*/
export function ignoreRequireCycleLogs(): void {
LogBox.ignoreLogs(['Require cycle:']);
export function ignoreRequireCycleLogs(version?: ReactNativeVersion): void {
if (version && version.major === 0 && version.minor < 70) {
// Do not ignore require cycle logs on React Native versions >= 0.70
// https://github.com/getsentry/sentry-react-native/issues/3484#issuecomment-1877034820
LogBox.ignoreLogs(['Require cycle:']);
}
}
2 changes: 1 addition & 1 deletion packages/core/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Tests ReactNativeClient', () => {
});

await expect(client.eventFromMessage('test')).resolves.toBeDefined();
await expect(RN.LogBox.ignoreLogs).toBeCalled();
await expect(RN.LogBox.ignoreLogs).not.toBeCalled();
});

test('invalid dsn is thrown', () => {
Expand Down
35 changes: 35 additions & 0 deletions packages/core/test/utils/ignorerequirecyclelogs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { LogBox } from 'react-native';

import { ignoreRequireCycleLogs } from '../../src/js/utils/ignorerequirecyclelogs';

jest.mock('react-native', () => ({
LogBox: {
ignoreLogs: jest.fn(),
},
}));

describe('ignoreRequireCycleLogs', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('should ignore logs for React Native version < 0.70', () => {
ignoreRequireCycleLogs({ major: 0, minor: 69 });
expect(LogBox.ignoreLogs).toHaveBeenCalledWith(['Require cycle:']);
});

it('should not ignore logs for React Native version 0.70', () => {
ignoreRequireCycleLogs({ major: 0, minor: 70 });
expect(LogBox.ignoreLogs).not.toHaveBeenCalled();
});

it('should not ignore logs for React Native version > 0.70', () => {
ignoreRequireCycleLogs({ major: 0, minor: 71 });
expect(LogBox.ignoreLogs).not.toHaveBeenCalled();
});

it('should not ignore logs when no version is passed', () => {
ignoreRequireCycleLogs();
expect(LogBox.ignoreLogs).not.toHaveBeenCalled();
});
});
Loading