Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
### Fixes

- Equalize TTID and TTFD duration when TTFD manual API is called and resolved before auto TTID ([#4680](https://github.com/getsentry/sentry-react-native/pull/4680))
- Avoid loading Sentry native components in Expo Go ([#4696](https://github.com/getsentry/sentry-react-native/pull/4696))

### Changes

Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/js/replay/CustomMask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as React from 'react';
import type { HostComponent, ViewProps } from 'react-native';
import { UIManager, View } from 'react-native';

import { isExpoGo } from '../utils/environment';

const NativeComponentRegistry: {
get<T, C extends Record<string, unknown>>(componentName: string, createViewConfig: () => C): HostComponent<T>;
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -35,7 +37,7 @@ const UnmaskFallback = (viewProps: ViewProps): React.ReactElement => {
const hasViewManagerConfig = (nativeComponentName: string): boolean => UIManager.hasViewManagerConfig && UIManager.hasViewManagerConfig(nativeComponentName);

const Mask = ((): HostComponent<ViewProps> | React.ComponentType<ViewProps> => {
if (!hasViewManagerConfig(MaskNativeComponentName)) {
if (isExpoGo() || !hasViewManagerConfig(MaskNativeComponentName)) {
logger.warn(`[SentrySessionReplay] Can't load ${MaskNativeComponentName}.`);
return MaskFallback;
}
Expand All @@ -48,7 +50,7 @@ const Mask = ((): HostComponent<ViewProps> | React.ComponentType<ViewProps> => {
})()

const Unmask = ((): HostComponent<ViewProps> | React.ComponentType<ViewProps> => {
if (!hasViewManagerConfig(UnmaskNativeComponentName)) {
if (isExpoGo() || !hasViewManagerConfig(UnmaskNativeComponentName)) {
logger.warn(`[SentrySessionReplay] Can't load ${UnmaskNativeComponentName}.`);
return UnmaskFallback;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/js/tracing/timetodisplaynative.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import type { HostComponent } from 'react-native';
import { UIManager, View } from 'react-native';

import { isExpoGo } from '../utils/environment';
import { ReactNativeLibraries } from '../utils/rnlibraries';
import type { RNSentryOnDrawReporterProps } from './timetodisplaynative.types';

Expand Down Expand Up @@ -29,7 +30,7 @@ let RNSentryOnDrawReporter: HostComponent<RNSentryOnDrawReporterProps> | typeof
*/
export const getRNSentryOnDrawReporter = (): typeof RNSentryOnDrawReporter => {
if (!RNSentryOnDrawReporter) {
RNSentryOnDrawReporter = nativeComponentExists && ReactNativeLibraries.ReactNative?.requireNativeComponent
RNSentryOnDrawReporter = !isExpoGo() && nativeComponentExists && ReactNativeLibraries.ReactNative?.requireNativeComponent
? ReactNativeLibraries.ReactNative.requireNativeComponent(RNSentryOnDrawReporterClass)
: RNSentryOnDrawReporterNoop;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/core/test/replay/CustomMask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ import { beforeEach, describe, expect, it } from '@jest/globals';

describe('CustomMask', () => {
beforeEach(() => {
jest.mock('../../src/js/utils/environment', () => ({
isExpoGo: () => false,
}));
jest.resetModules();
});

it('returns a fallback when isExpoGo is true', () => {
jest.mock('../../src/js/utils/environment', () => ({
isExpoGo: () => true,
}));

const { Mask, Unmask, MaskFallback, UnmaskFallback } = require('../../src/js/replay/CustomMask');

expect(Mask).toBe(MaskFallback);
expect(Unmask).toBe(UnmaskFallback);
});

it('returns a fallback when native view manager is missing', () => {
jest.mock('react-native', () => ({
UIManager: {},
Expand Down
15 changes: 15 additions & 0 deletions packages/core/test/tracing/timetodisplaynative.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getRNSentryOnDrawReporter } from '../../src/js/tracing/timetodisplaynative';
import * as Environment from '../../src/js/utils/environment';

describe('timetodisplaynative', () => {
beforeEach(() => {
jest.spyOn(Environment, 'isExpoGo').mockReturnValue(false);
});

test('getRNSentryOnDrawReporter returns Noop in Expo Go', () => {
jest.spyOn(Environment, 'isExpoGo').mockReturnValue(true);
const drawReported = getRNSentryOnDrawReporter();

expect(drawReported.name).toBe('RNSentryOnDrawReporterNoop');
});
});
Loading