Skip to content

Commit ed15ca3

Browse files
author
Luca Forstner
committed
Pull undefined check out of wrapper
1 parent c0577da commit ed15ca3

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/nextjs/src/config/loaders/dataFetchersLoader.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>,
144144
import { default as _sentry_default } from "${this.resourcePath}?sentry-proxy-loader";
145145
import { withSentryGetInitialProps } from "@sentry/nextjs";
146146
147-
_sentry_default.getInitialProps = withSentryGetInitialProps(_sentry_default.getInitialProps);
147+
if (typeof _sentry_default.getInitialProps === 'function') {
148+
_sentry_default.getInitialProps = withSentryGetInitialProps(_sentry_default.getInitialProps);
149+
}
148150
149151
export default _sentry_default;`;
150152
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import { GIProps } from './types';
1111
* @param origGIPropsHost: The user's object on which `getInitialProps` lives (used for `this`)
1212
* @returns A wrapped version of the function
1313
*/
14-
export function withSentryGetInitialProps(origGIProps: GIProps['fn'] | undefined): GIProps['wrappedFn'] {
15-
if (typeof origGIProps === 'function') {
16-
return async function (this: unknown, ...args: Parameters<GIProps['fn']>) {
17-
return await origGIProps.call(this, ...args);
18-
};
19-
} else {
20-
return origGIProps;
21-
}
14+
export function withSentryGetInitialProps(origGIProps: GIProps['fn']): GIProps['wrappedFn'] {
15+
return async function (this: unknown, ...args: Parameters<GIProps['fn']>) {
16+
return await origGIProps.call(this, ...args);
17+
};
2218
}

0 commit comments

Comments
 (0)