Skip to content

Commit

Permalink
Do not ignore require cycle logs for RN >= 0.70 (#4214)
Browse files Browse the repository at this point in the history
* Do not ignore require cycle logs for RN > 0.70

---------

Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com>
  • Loading branch information
antonis and lucas-zimerman authored Oct 31, 2024
1 parent 7b6b0bc commit 1faf8e3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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();
});
});

0 comments on commit 1faf8e3

Please sign in to comment.