From 84b1f5cb16bbb7a520cc4614a1af682ef3aaabac Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 2 Feb 2024 19:21:03 +0100 Subject: [PATCH] fix sdk main file --- src/js/sdk.tsx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/js/sdk.tsx b/src/js/sdk.tsx index 4a753d1da..adefddf1e 100644 --- a/src/js/sdk.tsx +++ b/src/js/sdk.tsx @@ -1,6 +1,6 @@ /* eslint-disable complexity */ import type { Scope } from '@sentry/core'; -import { getIntegrationsToSetup, Hub, initAndBind, makeMain, setExtra } from '@sentry/core'; +import { getClient, getIntegrationsToSetup, Hub, initAndBind, makeMain, setExtra, withScope as coreWithScope } from '@sentry/core'; import { defaultStackParser, getCurrentHub, @@ -16,7 +16,8 @@ import type { ReactNativeClientOptions, ReactNativeOptions, ReactNativeWrapperOp import { shouldEnableNativeNagger } from './options'; import { ReactNativeScope } from './scope'; import { TouchEventBoundary } from './touchevents'; -import { ReactNativeProfiler, ReactNativeTracing } from './tracing'; +import type { ReactNativeTracing } from './tracing'; +import { ReactNativeProfiler } from './tracing'; import { DEFAULT_BUFFER_SIZE, makeNativeTransportFactory } from './transports/native'; import { makeUtf8TextEncoder } from './transports/TextEncoder'; import { getDefaultEnvironment, isExpoGo } from './utils/environment'; @@ -45,6 +46,7 @@ const DEFAULT_OPTIONS: ReactNativeOptions = { */ export function init(passedOptions: ReactNativeOptions): void { const reactNativeHub = new Hub(undefined, new ReactNativeScope()); + // eslint-disable-next-line deprecation/deprecation makeMain(reactNativeHub); const maxQueueSize = passedOptions.maxQueueSize @@ -108,7 +110,7 @@ export function wrap

>( RootComponent: React.ComponentType

, options?: ReactNativeWrapperOptions ): React.ComponentType

{ - const tracingIntegration = getCurrentHub().getIntegration(ReactNativeTracing); + const tracingIntegration = getClient()?.getIntegrationByName?.('ReactNativeTracing') as ReactNativeTracing | undefined; if (tracingIntegration) { tracingIntegration.useAppStartWithProfiler = true; } @@ -154,10 +156,7 @@ export function setDist(dist: string): void { * Use this only for testing purposes. */ export function nativeCrash(): void { - const client = getCurrentHub().getClient(); - if (client) { - client.nativeCrash(); - } + NATIVE.nativeCrash(); } /** @@ -166,7 +165,7 @@ export function nativeCrash(): void { */ export async function flush(): Promise { try { - const client = getCurrentHub().getClient(); + const client = getClient(); if (client) { const result = await client.flush(); @@ -186,7 +185,7 @@ export async function flush(): Promise { */ export async function close(): Promise { try { - const client = getCurrentHub().getClient(); + const client = getClient(); if (client) { await client.close(); @@ -200,7 +199,7 @@ export async function close(): Promise { * Captures user feedback and sends it to Sentry. */ export function captureUserFeedback(feedback: UserFeedback): void { - getCurrentHub().getClient()?.captureUserFeedback(feedback); + getClient()?.captureUserFeedback(feedback); } /** @@ -225,12 +224,14 @@ export function withScope(callback: (scope: Scope) => T): T | undefined { return undefined; } }; - return getCurrentHub().withScope(safeCallback); + return coreWithScope(safeCallback); } /** * Callback to set context information onto the scope. * @param callback Callback function that receives Scope. + * + * @deprecated Use `getScope()` directly. */ export function configureScope(callback: (scope: Scope) => void): ReturnType { const safeCallback = (scope: Scope): void => { @@ -240,5 +241,6 @@ export function configureScope(callback: (scope: Scope) => void): ReturnType