Skip to content

Commit 2fa6855

Browse files
committed
stop wrapping getStaticPaths
1 parent 64c7204 commit 2fa6855

File tree

9 files changed

+19
-59
lines changed

9 files changed

+19
-59
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function maybeRenameNode(ast: AST, identifierPath: ASTPath<IdentifierNode>, alia
207207

208208
// In general we want to rename all nodes, unless we're in one of a few specific situations. (Anything which doesn't
209209
// get handled by one of these checks will be renamed at the end of this function.) In all of the scenarios below,
210-
// we'll use `gSSP` as our stand-in for any of `getServerSideProps`, `getStaticProps`, and `getStaticPaths`.
210+
// we'll use `gSSP` as our stand-in for either of `getServerSideProps` and `getStaticProps`.
211211

212212
// Imports:
213213
//
@@ -288,8 +288,8 @@ function maybeRenameNode(ast: AST, identifierPath: ASTPath<IdentifierNode>, alia
288288
//
289289
// Second, because need to wrap the object using its local name, we need to rename `local`. This tracks with how we
290290
// thought about `import` statements above, but is different from everything else we're doing in this function in that
291-
// it means we potentially need to rename something *not* already named `getServerSideProps`, `getStaticProps`, or
292-
// `getStaticPaths`, meaning we need to rename nodes outside of the collection upon which we're currently acting.
291+
// it means we potentially need to rename something *not* already named `getServerSideProps` or `getStaticProps`,
292+
// meaning we need to rename nodes outside of the collection upon which we're currently acting.
293293
if (ExportSpecifier.check(parent)) {
294294
// console.log(node);
295295
// debugger;

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
2-
* This loader auto-wraps a user's page-level data-fetching functions (`getStaticPaths`, `getStaticProps`, and
3-
* `getServerSideProps`) in order to instrument them for tracing. At a high level, this is done by finding the relevant
4-
* functions, renaming them so as not to create a name collision, and then creating a new version of each function which
5-
* is a wrapped version of the original. We do this by parsing the user's code and some template code into ASTs,
6-
* manipulating them, and then turning them back into strings and appending our template code to the user's (modified)
7-
* page code. Greater detail and explanations can be found in situ in the functions below and in the helper functions in
8-
* `ast.ts`.
2+
* This loader auto-wraps a user's page-level data-fetching functions (`getStaticProps` and `getServerSideProps`) in
3+
* order to instrument them for tracing. At a high level, this is done by finding the relevant functions, renaming them
4+
* so as not to create a name collision, and then creating a new version of each function which is a wrapped version of
5+
* the original. We do this by parsing the user's code and some template code into ASTs, manipulating them, and then
6+
* turning them back into strings and appending our template code to the user's (modified) page code. Greater detail and
7+
* explanations can be found in situ in the functions below and in the helper functions in `ast.ts`.
98
*/
109

1110
import { logger } from '@sentry/utils';
@@ -23,7 +22,6 @@ import type { LoaderThis } from './types';
2322
const DATA_FETCHING_FUNCTIONS = {
2423
getServerSideProps: { placeholder: '__ORIG_GSSP__', alias: '' },
2524
getStaticProps: { placeholder: '__ORIG_GSPROPS__', alias: '' },
26-
getStaticPaths: { placeholder: '__ORIG_GSPATHS__', alias: '' },
2725
};
2826

2927
type LoaderOptions = {
@@ -91,7 +89,7 @@ function wrapFunctions(userCode: string, templateCode: string, filepath: string)
9189
}
9290

9391
/**
94-
* Wrap `getStaticPaths`, `getStaticProps`, and `getServerSideProps` (if they exist) in the given page code
92+
* Wrap `getStaticProps` and `getServerSideProps` (if they exist) in the given page code
9593
*/
9694
export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>, userCode: string): string {
9795
// We know one or the other will be defined, depending on the version of webpack being used

packages/nextjs/src/config/templates/dataFetchersLoaderTemplate.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import type {
2-
GetServerSideProps as GetServerSidePropsFunction,
3-
GetStaticPaths as GetStaticPathsFunction,
4-
GetStaticProps as GetStaticPropsFunction,
5-
} from 'next';
1+
import type { GetServerSideProps as GetServerSidePropsFunction, GetStaticProps as GetStaticPropsFunction } from 'next';
62

73
declare const __ORIG_GSSP__: GetServerSidePropsFunction;
84
declare const __ORIG_GSPROPS__: GetStaticPropsFunction;
9-
declare const __ORIG_GSPATHS__: GetStaticPathsFunction;
105

116
// We import the SDK under a purposefully clunky name, to lessen to near zero the chances of a name collision in case
127
// the user has also imported Sentry for some reason. (In the future, we could check for such a collision using the AST,
@@ -28,7 +23,3 @@ export const getStaticProps =
2823
typeof __ORIG_GSPROPS__ === 'function'
2924
? ServerSideSentryNextjsSDK.withSentryGSProps(__ORIG_GSPROPS__)
3025
: __ORIG_GSPROPS__;
31-
export const getStaticPaths =
32-
typeof __ORIG_GSPATHS__ === 'function'
33-
? ServerSideSentryNextjsSDK.withSentryGSPaths(__ORIG_GSPATHS__)
34-
: __ORIG_GSPATHS__;

packages/nextjs/src/config/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export type UserSentryOptions = {
5151
widenClientFileUpload?: boolean;
5252

5353
experiments?: {
54-
// Automatically wrap `getServerSideProps`, `getStaticProps`, and `getStaticPaths` in order to instrument them for
55-
// tracing.
54+
// Automatically wrap `getServerSideProps` and `getStaticProps` in order to instrument them for tracing.
5655
autoWrapDataFetchers?: boolean;
5756
};
5857
};
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export { withSentryGSPaths } from './withSentryGSPaths';
21
export { withSentryGSProps } from './withSentryGSProps';
32
export { withSentryGSSP } from './withSentryGSSP';

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,13 @@ import type {
22
GetServerSideProps,
33
GetServerSidePropsContext,
44
GetServerSidePropsResult,
5-
GetStaticPaths,
6-
GetStaticPathsContext,
7-
GetStaticPathsResult,
85
GetStaticProps,
96
GetStaticPropsContext,
107
GetStaticPropsResult,
118
} from 'next';
129

13-
type Paths = { [key: string]: string | string[] };
1410
type Props = { [key: string]: unknown };
1511

16-
export type GSPaths = {
17-
fn: GetStaticPaths;
18-
wrappedFn: GetStaticPaths;
19-
context: GetStaticPathsContext;
20-
result: GetStaticPathsResult<Paths>;
21-
};
22-
2312
export type GSProps = {
2413
fn: GetStaticProps;
2514
wrappedFn: GetStaticProps;
@@ -34,4 +23,4 @@ export type GSSP = {
3423
result: GetServerSidePropsResult<Props>;
3524
};
3625

37-
export type DataFetchingFunction = GSPaths | GSProps | GSSP;
26+
export type DataFetchingFunction = GSProps | GSSP;

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

-16
This file was deleted.

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import { DataFetchingFunction } from './types';
44
* Pass-through wrapper for the original function, used as a first step in eventually wrapping the data-fetching
55
* functions with code for tracing.
66
*
7-
* @template T Types for `getStaticPaths`, `getStaticProps`, and `getServerSideProps`
8-
* @param origFunction The user's exported `getStaticPaths`, `getStaticProps`, or `getServerSideProps` function
7+
* @template T Types for `getStaticProps` and `getServerSideProps`
8+
* @param origFunction The user's exported `getStaticProps` or `getServerSideProps` function
99
* @param context The context object passed by nextjs to the function
1010
* @returns The result of calling the user's function
1111
*/
1212
export async function callOriginal<T extends DataFetchingFunction>(
1313
origFunction: T['fn'],
1414
context: T['context'],
1515
): Promise<T['result']> {
16-
let pathsOrProps;
16+
let props;
1717

1818
// TODO: Can't figure out how to tell TS that the types are correlated - that a `GSPropsFunction` will only get passed
1919
// `GSPropsContext` and never, say, `GSSPContext`. That's what wrapping everything in objects and using the generic
2020
// and pulling the types from the generic rather than specifying them directly was supposed to do, but... no luck.
2121
// eslint-disable-next-line prefer-const, @typescript-eslint/no-explicit-any
22-
pathsOrProps = await (origFunction as any)(context);
22+
props = await (origFunction as any)(context);
2323

24-
return pathsOrProps;
24+
return props;
2525
}

packages/nextjs/src/index.server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function addServerIntegrations(options: NextjsOptions): void {
125125
export type { SentryWebpackPluginOptions } from './config/types';
126126
export { withSentryConfig } from './config';
127127
export { isBuild } from './utils/isBuild';
128-
export { withSentryGSProps, withSentryGSSP, withSentryGSPaths } from './config/wrappers';
128+
export { withSentryGSProps, withSentryGSSP } from './config/wrappers';
129129
export { withSentry } from './utils/withSentry';
130130

131131
// Wrap various server methods to enable error monitoring and tracing. (Note: This only happens for non-Vercel

0 commit comments

Comments
 (0)