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