Skip to content

Commit f29f4b1

Browse files
authored
fix(nextjs): Export isomorphic data fetching wrappers from client SDK (#6790)
1 parent 28a430d commit f29f4b1

6 files changed

+170
-0
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,25 @@ function addClientIntegrations(options: BrowserOptions): void {
9292

9393
options.integrations = integrations;
9494
}
95+
96+
export {
97+
// eslint-disable-next-line deprecation/deprecation
98+
withSentryServerSideGetInitialProps,
99+
wrapGetInitialPropsWithSentry,
100+
} from './wrapGetInitialPropsWithSentry';
101+
102+
export {
103+
// eslint-disable-next-line deprecation/deprecation
104+
withSentryServerSideAppGetInitialProps,
105+
wrapAppGetInitialPropsWithSentry,
106+
} from './wrapAppGetInitialPropsWithSentry';
107+
export {
108+
// eslint-disable-next-line deprecation/deprecation
109+
withSentryServerSideDocumentGetInitialProps,
110+
wrapDocumentGetInitialPropsWithSentry,
111+
} from './wrapDocumentGetInitialPropsWithSentry';
112+
export {
113+
// eslint-disable-next-line deprecation/deprecation
114+
withSentryServerSideErrorGetInitialProps,
115+
wrapErrorGetInitialPropsWithSentry,
116+
} from './wrapErrorGetInitialPropsWithSentry';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type App from 'next/app';
2+
3+
type AppGetInitialProps = typeof App['getInitialProps'];
4+
5+
/**
6+
* A passthrough function in case this function is used on the clientside. We need to make the returned function async
7+
* so we are consistent with the serverside implementation.
8+
*/
9+
export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetInitialProps): AppGetInitialProps {
10+
return async function (this: unknown, ...args: Parameters<AppGetInitialProps>): ReturnType<AppGetInitialProps> {
11+
return await origAppGetInitialProps.apply(this, args);
12+
};
13+
}
14+
15+
/**
16+
* @deprecated Use `wrapAppGetInitialPropsWithSentry` instead.
17+
*/
18+
export const withSentryServerSideAppGetInitialProps = wrapAppGetInitialPropsWithSentry;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type Document from 'next/document';
2+
3+
type DocumentGetInitialProps = typeof Document.getInitialProps;
4+
5+
/**
6+
* A passthrough function in case this function is used on the clientside. We need to make the returned function async
7+
* so we are consistent with the serverside implementation.
8+
*/
9+
export function wrapDocumentGetInitialPropsWithSentry(
10+
origDocumentGetInitialProps: DocumentGetInitialProps,
11+
): DocumentGetInitialProps {
12+
return async function (
13+
this: unknown,
14+
...args: Parameters<DocumentGetInitialProps>
15+
): ReturnType<DocumentGetInitialProps> {
16+
return await origDocumentGetInitialProps.apply(this, args);
17+
};
18+
}
19+
20+
/**
21+
* @deprecated Use `wrapDocumentGetInitialPropsWithSentry` instead.
22+
*/
23+
export const withSentryServerSideDocumentGetInitialProps = wrapDocumentGetInitialPropsWithSentry;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { NextPageContext } from 'next';
2+
import type { ErrorProps } from 'next/error';
3+
4+
type ErrorGetInitialProps = (context: NextPageContext) => Promise<ErrorProps>;
5+
6+
/**
7+
* A passthrough function in case this function is used on the clientside. We need to make the returned function async
8+
* so we are consistent with the serverside implementation.
9+
*/
10+
export function wrapErrorGetInitialPropsWithSentry(
11+
origErrorGetInitialProps: ErrorGetInitialProps,
12+
): ErrorGetInitialProps {
13+
return async function (this: unknown, ...args: Parameters<ErrorGetInitialProps>): ReturnType<ErrorGetInitialProps> {
14+
return await origErrorGetInitialProps.apply(this, args);
15+
};
16+
}
17+
18+
/**
19+
* @deprecated Use `wrapErrorGetInitialPropsWithSentry` instead.
20+
*/
21+
export const withSentryServerSideErrorGetInitialProps = wrapErrorGetInitialPropsWithSentry;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { NextPage } from 'next';
2+
3+
type GetInitialProps = Required<NextPage>['getInitialProps'];
4+
5+
/**
6+
* A passthrough function in case this function is used on the clientside. We need to make the returned function async
7+
* so we are consistent with the serverside implementation.
8+
*/
9+
export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialProps): GetInitialProps {
10+
return async function (this: unknown, ...args: Parameters<GetInitialProps>): Promise<ReturnType<GetInitialProps>> {
11+
return origGetInitialProps.apply(this, args);
12+
};
13+
}
14+
15+
/**
16+
* @deprecated Use `wrapGetInitialPropsWithSentry` instead.
17+
*/
18+
export const withSentryServerSideGetInitialProps = wrapGetInitialPropsWithSentry;

packages/nextjs/src/index.types.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,71 @@ export declare function wrapApiHandlerWithSentry<APIHandler extends (...args: an
5353
): (
5454
...args: Parameters<APIHandler>
5555
) => ReturnType<APIHandler> extends Promise<unknown> ? ReturnType<APIHandler> : Promise<ReturnType<APIHandler>>;
56+
57+
/**
58+
* Wraps a `getInitialProps` function with Sentry error and performance instrumentation.
59+
*
60+
* @param getInitialProps The `getInitialProps` function
61+
* @returns A wrapped version of the function
62+
*/
63+
export declare function wrapGetInitialPropsWithSentry<F extends (...args: any[]) => any>(
64+
getInitialProps: F,
65+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
66+
67+
/**
68+
* @deprecated Use `wrapGetInitialPropsWithSentry` instead.
69+
*/
70+
export declare function withSentryServerSideGetInitialProps<F extends (...args: any[]) => any>(
71+
getInitialProps: F,
72+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
73+
74+
/**
75+
* Wraps a `getInitialProps` function of a custom `_app` page with Sentry error and performance instrumentation.
76+
*
77+
* @param getInitialProps The `getInitialProps` function
78+
* @returns A wrapped version of the function
79+
*/
80+
export declare function wrapAppGetInitialPropsWithSentry<F extends (...args: any[]) => any>(
81+
getInitialProps: F,
82+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
83+
84+
/**
85+
* @deprecated Use `wrapAppGetInitialPropsWithSentry` instead.
86+
*/
87+
export declare function withSentryServerSideAppGetInitialProps<F extends (...args: any[]) => any>(
88+
getInitialProps: F,
89+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
90+
91+
/**
92+
* Wraps a `getInitialProps` function of a custom `_document` page with Sentry error and performance instrumentation.
93+
*
94+
* @param getInitialProps The `getInitialProps` function
95+
* @returns A wrapped version of the function
96+
*/
97+
export declare function wrapDocumentGetInitialPropsWithSentry<F extends (...args: any[]) => any>(
98+
getInitialProps: F,
99+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
100+
101+
/**
102+
* @deprecated Use `wrapDocumentGetInitialPropsWithSentry` instead.
103+
*/
104+
export declare function withSentryServerSideDocumentGetInitialProps<F extends (...args: any[]) => any>(
105+
getInitialProps: F,
106+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
107+
108+
/**
109+
* Wraps a `getInitialProps` function of a custom `_error` page with Sentry error and performance instrumentation.
110+
*
111+
* @param getInitialProps The `getInitialProps` function
112+
* @returns A wrapped version of the function
113+
*/
114+
export declare function wrapErrorGetInitialPropsWithSentry<F extends (...args: any[]) => any>(
115+
getInitialProps: F,
116+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;
117+
118+
/**
119+
* @deprecated Use `wrapErrorGetInitialPropsWithSentry` instead.
120+
*/
121+
export declare function withSentryServerSideErrorGetInitialProps<F extends (...args: any[]) => any>(
122+
getInitialProps: F,
123+
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>>;

0 commit comments

Comments
 (0)