Skip to content

Commit 06d3a0a

Browse files
author
Luca Forstner
committed
Add no-null assertion about req and res in getInitialProps
1 parent 93ebc28 commit 06d3a0a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/nextjs/src/config/wrappers/withSentryServerSideGetInitialProps.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ export function withSentryServerSideGetInitialProps(
2424

2525
const errorWrappedGetInitialProps = withErrorInstrumentation(origGetInitialProps);
2626

27-
if (req && res && hasTracingEnabled()) {
28-
return callTracedServerSideDataFetcher(errorWrappedGetInitialProps, getInitialPropsArguments, req, res, {
27+
if (hasTracingEnabled()) {
28+
// Since this wrapper is only applied to `getInitialProps` running on the server, we can assert that `req` and
29+
// `res` are always defined: https://nextjs.org/docs/api-reference/data-fetching/get-initial-props#context-object
30+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
31+
return callTracedServerSideDataFetcher(errorWrappedGetInitialProps, getInitialPropsArguments, req!, res!, {
2932
parameterizedRoute,
3033
functionName: 'getInitialProps',
3134
});

0 commit comments

Comments
 (0)