Skip to content

fix(nextjs): Don't assert existence of req and res in data-fetching wrappers #5866

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

Merged
merged 2 commits into from
Oct 3, 2022

Conversation

lforst
Copy link
Contributor

@lforst lforst commented Oct 1, 2022

Fixes #5864

Next.js' getInitialProps functions generally are passed request and response objects on the server side. This does not seem to hold in development mode where there are cases that they're undefined.

This PR simply stops tracing getInitialProps functions when there are no request or response objects, because we have no clean way of grouping data fetchers under a transaction when there are no req and res objects.

Disclaimer: I am still not entirely sure if this is the right approach and how the exact behavior for getInitialProps and next dev is, but this is a forward fix to quickly unblock users.

@lforst lforst marked this pull request as ready for review October 3, 2022 07:03
// Generally we can assume that `req` and `res` are always defined on the server:
// https://nextjs.org/docs/api-reference/data-fetching/get-initial-props#context-object
// This does not seem to be the case in dev mode. Because we have no clean way of associating the the data fetcher
// span with eachother when there are no req or res objects, we simply do not trace them at all here.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// span with eachother when there are no req or res objects, we simply do not trace them at all here.
// span with each other when there are no req or res objects, we simply do not trace them at all here.

Copy link
Member

Choose a reason for hiding this comment

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

Ditto with the other comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

@lforst lforst enabled auto-merge (squash) October 3, 2022 07:38
@lforst lforst merged commit c09cab8 into master Oct 3, 2022
@lforst lforst deleted the lforst-dont-trace-when-req-is-missing branch October 3, 2022 08:00
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.

TypeError: Cannot read properties of undefined (reading '_sentryTransaction')
2 participants