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

fix(nextjs): Only apply tracing metadata to data fetcher data when data is an object #14575

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Dec 4, 2024

Resolves #14571

Technically this is unnecessary because Next.js requires data fetchers to return an object but still we don't want people thinking Sentry is the problem.

@lforst lforst requested a review from s1gr1d December 4, 2024 15:38
@@ -36,7 +36,7 @@ export function wrapGetServerSidePropsWithSentry(
sentryTrace,
} = await (tracedGetServerSideProps.apply(thisArg, args) as ReturnType<typeof tracedGetServerSideProps>);

if (serverSideProps && 'props' in serverSideProps) {
if (typeof serverSideProps === 'object' && 'props' in serverSideProps) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify...do you want to include null (and other) values here? because typeof null === 'object'

You could check for serverSideProps.constructor.name === "Object" if you specifically look for an object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the joys of any :D If we want to make this safe I would do:

serverSideProps && typeof serverSideProps === 'object' && 'props' in serverSideProps

If you make serverSideProps: unknown then this is what actually "works" in a type safe way, I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason I fumbled this one and the errorgetinitialprops one

@lforst lforst requested review from s1gr1d and mydea December 5, 2024 09:09
Copy link
Member

@s1gr1d s1gr1d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@lforst lforst merged commit c6ae78b into develop Dec 5, 2024
153 checks passed
@lforst lforst deleted the lforst-safeguard-undefined branch December 5, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot set properties of undefined (setting '_sentryTraceData')
3 participants