Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set properties of undefined (setting '_sentryTraceData') #14571

Closed
3 tasks done
Grohden opened this issue Dec 4, 2024 · 4 comments · Fixed by #14575
Closed
3 tasks done

Cannot set properties of undefined (setting '_sentryTraceData') #14571

Grohden opened this issue Dec 4, 2024 · 4 comments · Fixed by #14575
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK

Comments

@Grohden
Copy link

Grohden commented Dec 4, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

8.35.0

Framework Version

Next 14.2.11

Link to Sentry event

https://trusted-health.sentry.io/issues/5833907467/events/651aec0e738f4a8592762072abecec34/

Reproduction Example/SDK Setup

We've been having this issue for a while AFAIK, so here's what we've investigated

From the linked stack trace, these are the lines:

const {
data: initialProps,
baggage,
sentryTrace,
}: {
data: {
_sentryTraceData?: string;
_sentryBaggage?: string;
};
baggage?: string;
sentryTrace?: string;
} = (await tracedGetInitialProps.apply(thisArg, args)) ?? {}; // Next.js allows undefined to be returned from a getInitialPropsFunction.

If (await tracedGetInitialProps.apply(thisArg, args)) results in undefined we get a {} default

But then all these:

const {
          data: initialProps, // undefined
          baggage, // undefined
          sentryTrace, // undefined
} = {}

become undefined, so we're executing this:

        // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
        if (sentryTrace) {
          undefined._sentryTraceData = sentryTrace;
        }

Which will result in those undefined access problems...

You guys also have some other places where there's similar code that might be worth checking
https://github.com/search?q=repo%3Agetsentry%2Fsentry-javascript+tracedGetInitialProps.apply%28thisArg%2C+args%29%29&type=code

It also seems sentry had a similar issue in the past

Steps to Reproduce

Don't know how to simulate

Expected Result

No throw

Actual Result

Throw

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 4, 2024
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Dec 4, 2024
@Grohden
Copy link
Author

Grohden commented Dec 4, 2024

btw I guess it just needs the proper ts cast there.. data is typed as non optional

@lforst lforst self-assigned this Dec 4, 2024
@lforst
Copy link
Member

lforst commented Dec 4, 2024

Thanks for writing in! So technically Next.js doesn't allow returning undefined from getInitialProps, so your app will crash regardless. I'll still add a safeguard so that people don't think it is Sentry causing issues.

@Grohden
Copy link
Author

Grohden commented Dec 4, 2024

@lforst oh well, then it should crash, but it doesn't :/, but yeah, at least not crash on sentry traces so we don't bother you all with these

Our robots.txt page work fine without returning something
Image

We're adding the {} return there but all seemed to work :/

Copy link
Contributor

A PR closing this issue has just been released 🚀

This issue was referenced by PR #14575, which was included in the 8.43.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK
Projects
Archived in project
2 participants