reduce Sentry web bundle footprint

This commit is contained in:
Oleksii Bulenok
2026-08-13 13:17:12 +02:00
parent 43b0c8b021
commit a9c16ef67e
6 changed files with 48 additions and 4 deletions
+13
View File
@@ -326,6 +326,10 @@
"default"
],
"message": "React is already in the global type namespace. Use named imports for runtime modules."
},
{
"name": "@sentry/react-native",
"message": "Import {Sentry} from '#/logger/sentry/lib' instead. Importing @sentry/react-native directly (especially as `import * as Sentry`) defeats Metro tree-shaking and pulls ~180KB of dead weight into the web bundle."
}
]
}
@@ -401,6 +405,15 @@
"env": {
"jest": true
}
},
{
"files": [
"src/logger/sentry/**/*.ts",
"src/logger/__tests__/logger.test.ts"
],
"rules": {
"no-restricted-imports": "off"
}
}
]
}
+1
View File
@@ -6,6 +6,7 @@ import {getSentryExpoConfig} from '@sentry/react-native/metro.js'
const config = getSentryExpoConfig(import.meta.dirname, {
// TODO: confirm this doesn't break anything when we switch to metro web
includeWebReplay: false,
includeWebFeedback: false,
annotateReactComponents: {
textComponentNames: ['Text', 'ButtonText'],
},
+1 -1
View File
@@ -11,7 +11,6 @@ import * as ScreenOrientation from 'expo-screen-orientation'
import * as SplashScreen from 'expo-splash-screen'
import * as SystemUI from 'expo-system-ui'
import {useLingui} from '@lingui/react/macro'
import * as Sentry from '@sentry/react-native'
import {Provider as HideBottomBarBorderProvider} from '#/lib/hooks/useHideBottomBarBorder'
import {QueryProvider} from '#/lib/react-query'
@@ -19,6 +18,7 @@ import {ThemeProvider} from '#/lib/ThemeContext'
import {Provider as TranslateOnDeviceProvider} from '#/lib/translation'
import I18nProvider from '#/locale/i18nProvider'
import {logger} from '#/logger'
import {Sentry} from '#/logger/sentry/lib'
import {Provider as A11yProvider} from '#/state/a11y'
import {
prefetchAppConfig,
+1 -1
View File
@@ -5,7 +5,6 @@ import {Fragment, useEffect, useState} from 'react'
import {KeyboardProvider as KeyboardControllerProvider} from 'react-native-keyboard-controller'
import {SafeAreaProvider} from 'react-native-safe-area-context'
import {useLingui} from '@lingui/react/macro'
import * as Sentry from '@sentry/react-native'
import {Provider as HotkeysProvider} from '#/lib/hotkeys'
import {QueryProvider} from '#/lib/react-query'
@@ -13,6 +12,7 @@ import {ThemeProvider} from '#/lib/ThemeContext'
import {Provider as TranslateOnDeviceProvider} from '#/lib/translation'
import I18nProvider from '#/locale/i18nProvider'
import {logger} from '#/logger'
import {Sentry} from '#/logger/sentry/lib'
import {Provider as A11yProvider} from '#/state/a11y'
import {
prefetchAppConfig,
+32 -1
View File
@@ -1 +1,32 @@
export * as Sentry from '@sentry/react-native'
import {
addBreadcrumb,
captureException,
captureFeedback,
captureMessage,
getClient,
startInactiveSpan,
withActiveSpan,
withScope,
wrap,
} from '@sentry/react-native'
/**
* Curated subset of @sentry/react-native, listing only the symbols the app
* actually uses. Re-exporting the whole SDK namespace
* (`export * as Sentry from '@sentry/react-native'`) defeats Metro
* tree-shaking on web and pulls in ~180KB of dead weight.
*
* When the app needs another SDK function, add it to the import above and to
* this object, then run a web build to confirm the bundle size is unaffected.
*/
export const Sentry = {
addBreadcrumb,
captureException,
captureFeedback,
captureMessage,
getClient,
startInactiveSpan,
withActiveSpan,
withScope,
wrap,
}
-1
View File
@@ -1 +0,0 @@
export * as Sentry from '@sentry/react-native'