diff --git a/CHANGELOG.md b/CHANGELOG.md index 3118925cc..d761f0b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixes +- Skips ignoring require cycle logs for RN 0.70 or newer ([#4214](https://github.com/getsentry/sentry-react-native/pull/4214)) - Enhanced accuracy of time-to-display spans. ([#4189](https://github.com/getsentry/sentry-react-native/pull/4189)) ### Dependencies diff --git a/packages/core/src/js/client.ts b/packages/core/src/js/client.ts index f01f6d98b..0497df97d 100644 --- a/packages/core/src/js/client.ts +++ b/packages/core/src/js/client.ts @@ -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'; /** @@ -37,7 +38,7 @@ export class ReactNativeClient extends BaseClient { * @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 diff --git a/packages/core/src/js/utils/ignorerequirecyclelogs.ts b/packages/core/src/js/utils/ignorerequirecyclelogs.ts index 7df3a3f00..db9897d3f 100644 --- a/packages/core/src/js/utils/ignorerequirecyclelogs.ts +++ b/packages/core/src/js/utils/ignorerequirecyclelogs.ts @@ -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:']); + } } diff --git a/packages/core/test/client.test.ts b/packages/core/test/client.test.ts index 955f10bce..a0e5b1320 100644 --- a/packages/core/test/client.test.ts +++ b/packages/core/test/client.test.ts @@ -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', () => { diff --git a/packages/core/test/utils/ignorerequirecyclelogs.test.ts b/packages/core/test/utils/ignorerequirecyclelogs.test.ts new file mode 100644 index 000000000..11f62b9d2 --- /dev/null +++ b/packages/core/test/utils/ignorerequirecyclelogs.test.ts @@ -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(); + }); +});