@@ -41,32 +41,29 @@ export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetI
41
41
sentryTrace,
42
42
baggage,
43
43
} : {
44
- data : {
45
- pageProps : {
46
- _sentryTraceData ?: string ;
47
- _sentryBaggage ?: string ;
48
- } ;
49
- } ;
44
+ data ?: unknown ;
50
45
sentryTrace ?: string ;
51
46
baggage ?: string ;
52
47
} = await tracedGetInitialProps . apply ( thisArg , args ) ;
53
48
54
- // Per definition, `pageProps` is not optional, however an increased amount of users doesn't seem to call
55
- // `App.getInitialProps(appContext)` in their custom `_app` pages which is required as per
56
- // https://nextjs.org/docs/advanced-features/custom-app - resulting in missing `pageProps`.
57
- // For this reason, we just handle the case where `pageProps` doesn't exist explicitly.
58
- if ( ! appGetInitialProps . pageProps ) {
59
- appGetInitialProps . pageProps = { } ;
60
- }
49
+ if ( typeof appGetInitialProps === 'object' && appGetInitialProps !== null ) {
50
+ // Per definition, `pageProps` is not optional, however an increased amount of users doesn't seem to call
51
+ // `App.getInitialProps(appContext)` in their custom `_app` pages which is required as per
52
+ // https://nextjs.org/docs/advanced-features/custom-app - resulting in missing `pageProps`.
53
+ // For this reason, we just handle the case where `pageProps` doesn't exist explicitly.
54
+ if ( ! ( appGetInitialProps as Record < string , unknown > ) . pageProps ) {
55
+ ( appGetInitialProps as Record < string , unknown > ) . pageProps = { } ;
56
+ }
61
57
62
- // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
63
- if ( sentryTrace ) {
64
- appGetInitialProps . pageProps . _sentryTraceData = sentryTrace ;
65
- }
58
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
59
+ if ( sentryTrace ) {
60
+ ( appGetInitialProps as { pageProps : Record < string , unknown > } ) . pageProps . _sentryTraceData = sentryTrace ;
61
+ }
66
62
67
- // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
68
- if ( baggage ) {
69
- appGetInitialProps . pageProps . _sentryBaggage = baggage ;
63
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
64
+ if ( baggage ) {
65
+ ( appGetInitialProps as { pageProps : Record < string , unknown > } ) . pageProps . _sentryBaggage = baggage ;
66
+ }
70
67
}
71
68
72
69
return appGetInitialProps ;
0 commit comments