diff --git a/CHANGELOG.md b/CHANGELOG.md index bb57c47337..cdcc75d1f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - expo-upload-sourcemaps now works on Windows ([#3643](https://github.com/getsentry/sentry-react-native/pull/3643)) - Option `enabled: false` ensures no events are sent ([#3606](https://github.com/getsentry/sentry-react-native/pull/3606)) - Ignore JSON response when retrieving source context from local Expo Dev Server ([#3611](https://github.com/getsentry/sentry-react-native/pull/3611)) +- Reduce waning messages spam when a property in Expo plugin configuration is missing ([#3631](https://github.com/getsentry/sentry-react-native/pull/3631)) +- `TurboModuleRegistry` should not be imported in web applications ([#3610](https://github.com/getsentry/sentry-react-native/pull/3610)) ### Dependencies diff --git a/src/js/utils/rnlibraries.ts b/src/js/utils/rnlibraries.ts index f00c8c5236..1cca394030 100644 --- a/src/js/utils/rnlibraries.ts +++ b/src/js/utils/rnlibraries.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-var-requires */ +import { TurboModuleRegistry } from 'react-native'; import { version as RNV } from 'react-native/Libraries/Core/ReactNativeVersion'; import type * as ReactNative from '../vendor/react-native'; @@ -33,4 +34,5 @@ export const ReactNativeLibraries: Required = { ReactNativeVersion: { version: RNV, }, + TurboModuleRegistry, }; diff --git a/src/js/utils/rnlibrariesinterface.ts b/src/js/utils/rnlibrariesinterface.ts index eff652a33a..9250398321 100644 --- a/src/js/utils/rnlibrariesinterface.ts +++ b/src/js/utils/rnlibrariesinterface.ts @@ -28,4 +28,5 @@ export interface ReactNativeLibrariesInterface { ReactNativeVersion?: { version: typeof RNV; }; + TurboModuleRegistry?: ReactNative.TurboModuleRegistry; } diff --git a/src/js/vendor/react-native/index.ts b/src/js/vendor/react-native/index.ts index d3affa091c..de54382381 100644 --- a/src/js/vendor/react-native/index.ts +++ b/src/js/vendor/react-native/index.ts @@ -53,3 +53,14 @@ export type DevServerInfo = { fullBundleUrl?: string; bundleLoadedFromServer: boolean; }; + +// Adapted from https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/TurboModule/RCTExport.d.ts#L10 +type TurboModule = { + getConstants?(): object; +}; + +// Adapted from https://github.com/facebook/react-native/blob/d09c02f9e2d468e4d0bde51890e312ae7003a3e6/packages/react-native/Libraries/TurboModule/TurboModuleRegistry.d.ts#L12 +export type TurboModuleRegistry = { + get(name: string): T | null; + getEnforcing(name: string): T; +}; diff --git a/src/js/wrapper.ts b/src/js/wrapper.ts index a5bdd8a50d..40d55ebc09 100644 --- a/src/js/wrapper.ts +++ b/src/js/wrapper.ts @@ -10,7 +10,7 @@ import type { User, } from '@sentry/types'; import { logger, normalize, SentryError } from '@sentry/utils'; -import { NativeModules, Platform, TurboModuleRegistry } from 'react-native'; +import { NativeModules, Platform } from 'react-native'; import { isHardCrash } from './misc'; import type { @@ -27,10 +27,11 @@ import type * as Hermes from './profiling/hermes'; import type { NativeAndroidProfileEvent, NativeProfileEvent } from './profiling/nativeTypes'; import type { RequiredKeysUser } from './user'; import { isTurboModuleEnabled } from './utils/environment'; +import { ReactNativeLibraries } from './utils/rnlibraries'; import { base64StringFromByteArray, utf8ToBytes } from './vendor'; const RNSentry: Spec | undefined = isTurboModuleEnabled() - ? TurboModuleRegistry.get('RNSentry') + ? ReactNativeLibraries.TurboModuleRegistry && ReactNativeLibraries.TurboModuleRegistry.get('RNSentry') : NativeModules.RNSentry; export interface Screenshot {