Skip to content

Commit 52c0562

Browse files
Fix: Add check version to new arch on TimetoTisplay (#4160)
* add check version to new arch * screen rename, nits on if condition * lint? * lint * lint * make more data from sample, requested changes * remove before effect
1 parent 4412b4c commit 52c0562

File tree

6 files changed

+129
-2
lines changed

6 files changed

+129
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- TimetoTisplay correctly warns about not supporting the new React Native architecture ([#4160](https://github.com/getsentry/sentry-react-native/pull/4160))
78
- Handles error with string cause ([#4163](https://github.com/getsentry/sentry-react-native/pull/4163))
89
- Use `appLaunchedInForeground` to determine invalid app start data on Android ([#4146](https://github.com/getsentry/sentry-react-native/pull/4146))
910
- Upload source maps for all release variants on Android (not only the last found) ([#4125](https://github.com/getsentry/sentry-react-native/pull/4125))

samples/react-native/src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { HttpClient } from '@sentry/integrations';
3333
import Ionicons from 'react-native-vector-icons/Ionicons';
3434
import PlaygroundScreen from './Screens/PlaygroundScreen';
3535
import { logWithoutTracing } from './utils';
36+
import HeavyNavigationScreen from './Screens/HeavyNavigationScreen';
3637

3738
LogBox.ignoreAllLogs();
3839

@@ -168,6 +169,10 @@ const TabTwoStack = Sentry.withProfiler(
168169
name="ManualTracker"
169170
component={ManualTrackerScreen}
170171
/>
172+
<Stack.Screen
173+
name="HeavyNavigation"
174+
component={HeavyNavigationScreen}
175+
/>
171176
<Stack.Screen
172177
name="PerformanceTiming"
173178
component={PerformanceTimingScreen}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as React from 'react';
2+
import { Button, View, StyleSheet, Text, ScrollView } from 'react-native';
3+
4+
import * as Sentry from '@sentry/react-native';
5+
import { StackNavigationProp } from '@react-navigation/stack';
6+
7+
interface Props {
8+
navigation: StackNavigationProp<any, 'HeavyNatigavionScreen'>;
9+
route?: {
10+
params?: {
11+
manualTrack: boolean;
12+
};
13+
};
14+
}
15+
const buttonTitles = Array.from(
16+
{ length: 500 },
17+
(_, index) => `Sample button ${index + 1}`,
18+
);
19+
20+
/**
21+
* this page takes around 300ms to initially display, we navigate to another page in 100ms.
22+
* The time to initial display will never be finished on this page.
23+
*/
24+
const HeavyNavigationScreen = (props: Props) => {
25+
const content = (
26+
<ScrollView style={styles.screen}>
27+
<View style={styles.titleContainer}>
28+
<Text style={styles.title}>
29+
Heavy page only intended for navigating to another page while the page
30+
is loading.
31+
</Text>
32+
</View>
33+
{buttonTitles.map((title, index) => (
34+
<Button key={index} title={title} />
35+
))}
36+
</ScrollView>
37+
);
38+
39+
React.useEffect(() => {
40+
setTimeout(() => {
41+
props.navigation.goBack();
42+
}, 1);
43+
});
44+
return (
45+
<>
46+
{props.route?.params?.manualTrack ? (
47+
<Sentry.TimeToInitialDisplay record={true}>
48+
{content}
49+
</Sentry.TimeToInitialDisplay>
50+
) : (
51+
content
52+
)}
53+
</>
54+
);
55+
};
56+
57+
export default Sentry.withProfiler(HeavyNavigationScreen);
58+
59+
const styles = StyleSheet.create({
60+
screen: {
61+
flex: 1,
62+
padding: 16,
63+
},
64+
titleContainer: {
65+
paddingBottom: 12,
66+
},
67+
title: {
68+
fontSize: 24,
69+
fontWeight: '700',
70+
},
71+
});

samples/react-native/src/Screens/PerformanceScreen.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ import {
1111
import { StackNavigationProp } from '@react-navigation/stack';
1212
import { CommonActions } from '@react-navigation/native';
1313
import * as Sentry from '@sentry/react-native';
14+
import { Text } from 'react-native';
1415

1516
interface Props {
1617
navigation: StackNavigationProp<any, 'PerformanceScreen'>;
1718
}
1819

20+
const Spacer = () => <View style={styles.spacer} />;
21+
1922
const PerformanceScreen = (props: Props) => {
2023
const onPressPerformanceTiming = () => {
2124
// Navigate with a reset action just to test
@@ -62,6 +65,24 @@ const PerformanceScreen = (props: Props) => {
6265
props.navigation.navigate('Redux');
6366
}}
6467
/>
68+
<Spacer />
69+
<Text>
70+
Heavy Page Navigation that navigates back automatically, before
71+
finishing the time to display.
72+
</Text>
73+
<Button
74+
title="With Manual TimeToDisplay."
75+
onPress={() => {
76+
props.navigation.navigate('HeavyNavigation', { manualTrack: true });
77+
}}
78+
/>
79+
<Button
80+
title="With Automatic TimeToDisplay."
81+
onPress={() => {
82+
props.navigation.navigate('HeavyNavigation');
83+
}}
84+
/>
85+
<Spacer />
6586
<View style={styles.mainViewBottomWhiteSpace} />
6687
</ScrollView>
6788
</>

src/js/tracing/timetodisplay.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Span,StartSpanOptions } from '@sentry/types';
33
import { fill, logger } from '@sentry/utils';
44
import * as React from 'react';
55

6+
import { isTurboModuleEnabled } from '../utils/environment';
67
import { getRNSentryOnDrawReporter, nativeComponentExists } from './timetodisplaynative';
78
import type {RNSentryOnDrawNextFrameEvent } from './timetodisplaynative.types';
89
import { setSpanDurationAsMeasurement } from './utils';
@@ -59,12 +60,14 @@ function TimeToDisplay(props: {
5960
fullDisplay?: boolean;
6061
}): React.ReactElement {
6162
const RNSentryOnDrawReporter = getRNSentryOnDrawReporter();
63+
const isNewArchitecture = isTurboModuleEnabled();
6264

63-
if (__DEV__ && !nativeComponentMissingLogged && !nativeComponentExists) {
65+
if (__DEV__ && (isNewArchitecture || (!nativeComponentExists && !nativeComponentMissingLogged))){
6466
nativeComponentMissingLogged = true;
6567
// Using setTimeout with a delay of 0 milliseconds to defer execution and avoid printing the React stack trace.
6668
setTimeout(() => {
67-
logger.warn('TimeToInitialDisplay and TimeToFullDisplay are not supported on the web, Expo Go and New Architecture. Run native build or report an issue at https://github.com/getsentry/sentry-react-native');
69+
logger.warn(
70+
'TimeToInitialDisplay and TimeToFullDisplay are not supported on the web, Expo Go and New Architecture. Run native build or report an issue at https://github.com/getsentry/sentry-react-native');
6871
}, 0);
6972
}
7073

test/tracing/timetodisplay.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import * as mockedtimetodisplaynative from './mockedtimetodisplaynative';
22
jest.mock('../../src/js/tracing/timetodisplaynative', () => mockedtimetodisplaynative);
3+
import { isTurboModuleEnabled } from '../../src/js/utils/environment';
4+
jest.mock('../../src/js/utils/environment', () => ({
5+
isTurboModuleEnabled: jest.fn().mockReturnValue(false),
6+
}));
7+
jest.spyOn(logger, 'warn');
38

49
import type { Span as SpanClass} from '@sentry/core';
510
import { getActiveSpan, getCurrentScope, getGlobalScope, getIsolationScope, setCurrentClient, spanToJSON, startSpanManual} from '@sentry/core';
611
import type { Event, Measurements, Span, SpanJSON} from '@sentry/types';
12+
import { logger } from '@sentry/utils';
713
import React from "react";
814
import TestRenderer from 'react-test-renderer';
915

@@ -373,6 +379,26 @@ describe('TimeToDisplay', () => {
373379
expect(spanToJSON(initialDisplaySpan!).timestamp).toEqual(initialDisplayEndTimestampMs / 1_000);
374380
expect(spanToJSON(fullDisplaySpan!).timestamp).toEqual(fullDisplayEndTimestampMs / 1_000);
375381
});
382+
383+
test('should not log a warning if native component exists and not in new architecture', async () => {
384+
385+
(isTurboModuleEnabled as jest.Mock).mockReturnValue(false);
386+
387+
TestRenderer.create(<TimeToInitialDisplay record={true} />);
388+
await jest.runOnlyPendingTimersAsync(); // Flush setTimeout.
389+
390+
expect(logger.warn).not.toHaveBeenCalled();
391+
});
392+
393+
test('should log a warning if in new architecture', async () => {
394+
395+
(isTurboModuleEnabled as jest.Mock).mockReturnValue(true);
396+
TestRenderer.create(<TimeToInitialDisplay record={true} />);
397+
await jest.runOnlyPendingTimersAsync(); // Flush setTimeout.
398+
399+
expect(logger.warn).toHaveBeenCalledWith(
400+
'TimeToInitialDisplay and TimeToFullDisplay are not supported on the web, Expo Go and New Architecture. Run native build or report an issue at https://github.com/getsentry/sentry-react-native');
401+
});
376402
});
377403

378404
function getInitialDisplaySpan(span?: Span) {

0 commit comments

Comments
 (0)