@@ -11,6 +11,8 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
1111import useTheme from '@hooks/useTheme' ;
1212import useThemeStyles from '@hooks/useThemeStyles' ;
1313import type { TabNavigatorParamList } from '@libs/Navigation/types' ;
14+ import { getSpan } from '@libs/telemetry/activeSpans' ;
15+ import CONST from '@src/CONST' ;
1416import NAVIGATORS from '@src/NAVIGATORS' ;
1517import SCREENS from '@src/SCREENS' ;
1618import TabNavigatorBar from './TabNavigatorBar' ;
@@ -21,20 +23,36 @@ const LazySearchFullscreenNavigator = lazy(() => import('./SearchFullscreenNavig
2123const LazySettingsSplitNavigator = lazy ( ( ) => import ( './SettingsSplitNavigator' ) ) ;
2224const LazyWorkspaceNavigator = lazy ( ( ) => import ( './WorkspaceNavigator' ) ) ;
2325
24- function withSuspense < P extends Record < string , unknown > > ( LazyComponent : React . LazyExoticComponent < React . ComponentType < P > > ) {
26+ type LazyFallbackProps = {
27+ /** Sentry span to tag when this fallback renders. */
28+ tabSpanName ?: string ;
29+ } ;
30+
31+ function LazyFallback ( { tabSpanName} : LazyFallbackProps ) {
32+ const styles = useThemeStyles ( ) ;
33+
34+ // Lets Sentry split slow tab navigations into "lazy chunk fetch" vs "screen render" buckets.
35+ useEffect ( ( ) => {
36+ if ( ! tabSpanName ) {
37+ return ;
38+ }
39+ getSpan ( tabSpanName ) ?. setAttribute ( CONST . TELEMETRY . ATTRIBUTE_LAZY_TAB_FALLBACK_SHOWN , true ) ;
40+ } , [ tabSpanName ] ) ;
41+
42+ return (
43+ < View style = { [ styles . flex1 , styles . justifyContentCenter , styles . alignItemsCenter , styles . appBG ] } >
44+ < ActivityIndicator
45+ size = "large"
46+ reasonAttributes = { { context : 'TabNavigator.LazyTab' } }
47+ />
48+ </ View >
49+ ) ;
50+ }
51+
52+ function withSuspense < P extends Record < string , unknown > > ( LazyComponent : React . LazyExoticComponent < React . ComponentType < P > > , tabSpanName ?: string ) {
2553 function SuspenseWrapper ( props : P ) {
26- const styles = useThemeStyles ( ) ;
2754 return (
28- < Suspense
29- fallback = {
30- < View style = { [ styles . flex1 , styles . justifyContentCenter , styles . alignItemsCenter , styles . appBG ] } >
31- < ActivityIndicator
32- size = "large"
33- reasonAttributes = { { context : 'TabNavigator.LazyTab' } }
34- />
35- </ View >
36- }
37- >
55+ < Suspense fallback = { < LazyFallback tabSpanName = { tabSpanName } /> } >
3856 { /* eslint-disable-next-line react/jsx-props-no-spreading */ }
3957 < LazyComponent { ...props } />
4058 </ Suspense >
@@ -44,8 +62,8 @@ function withSuspense<P extends Record<string, unknown>>(LazyComponent: React.La
4462}
4563
4664const HomePageScreen = withSuspense ( LazyHomePage ) ;
47- const ReportsSplitNavigatorScreen = withSuspense ( LazyReportsSplitNavigator ) ;
48- const SearchFullscreenNavigatorScreen = withSuspense ( LazySearchFullscreenNavigator ) ;
65+ const ReportsSplitNavigatorScreen = withSuspense ( LazyReportsSplitNavigator , CONST . TELEMETRY . SPAN_NAVIGATE_TO_INBOX_TAB ) ;
66+ const SearchFullscreenNavigatorScreen = withSuspense ( LazySearchFullscreenNavigator , CONST . TELEMETRY . SPAN_NAVIGATE_TO_REPORTS ) ;
4967const SettingsSplitNavigatorScreen = withSuspense ( LazySettingsSplitNavigator ) ;
5068const WorkspaceNavigatorScreen = withSuspense ( LazyWorkspaceNavigator ) ;
5169
0 commit comments