Skip to content

Commit 75f77c4

Browse files
author
Luca Forstner
committed
unfumble
1 parent a679290 commit 75f77c4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/nextjs/src/common/pages-router-instrumentation/wrapErrorGetInitialPropsWithSentry.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ export function wrapErrorGetInitialPropsWithSentry(
4848
sentryTrace?: string;
4949
} = await tracedGetInitialProps.apply(thisArg, args);
5050

51-
// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
52-
if (sentryTrace) {
53-
(errorGetInitialProps as Record<string, unknown>)._sentryTraceData = sentryTrace;
54-
}
51+
if (typeof errorGetInitialProps === 'object' && errorGetInitialProps !== null) {
52+
if (sentryTrace) {
53+
// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
54+
(errorGetInitialProps as Record<string, unknown>)._sentryTraceData = sentryTrace;
55+
}
5556

56-
// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
57-
if (baggage) {
58-
(errorGetInitialProps as Record<string, unknown>)._sentryBaggage = baggage;
57+
// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
58+
if (baggage) {
59+
(errorGetInitialProps as Record<string, unknown>)._sentryBaggage = baggage;
60+
}
5961
}
6062

6163
return errorGetInitialProps;

packages/nextjs/src/common/pages-router-instrumentation/wrapGetServerSidePropsWithSentry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ export function wrapGetServerSidePropsWithSentry(
3434
data: serverSideProps,
3535
baggage,
3636
sentryTrace,
37+
}: {
38+
data?: unknown;
39+
baggage?: string;
40+
sentryTrace?: string;
3741
} = await (tracedGetServerSideProps.apply(thisArg, args) as ReturnType<typeof tracedGetServerSideProps>);
3842

39-
if (typeof serverSideProps === 'object' && 'props' in serverSideProps) {
43+
if (typeof serverSideProps === 'object' && serverSideProps !== null && 'props' in serverSideProps) {
4044
// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
4145
if (sentryTrace) {
4246
(serverSideProps.props as Record<string, unknown>)._sentryTraceData = sentryTrace;

0 commit comments

Comments
 (0)