Skip to content

Commit 521d21a

Browse files
lobsterkatielforst
authored andcommitted
stop wrapping getStaticPaths
1 parent 2e07b78 commit 521d21a

File tree

8 files changed

+19
-48
lines changed

8 files changed

+19
-48
lines changed

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

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

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

222222
// Imports:
223223
//
@@ -298,8 +298,8 @@ function maybeRenameNode(ast: AST, identifierPath: ASTPath<IdentifierNode>, alia
298298
//
299299
// Second, because need to wrap the object using its local name, we need to rename `local`. This tracks with how we
300300
// thought about `import` statements above, but is different from everything else we're doing in this function in that
301-
// it means we potentially need to rename something *not* already named `getServerSideProps`, `getStaticProps`, or
302-
// `getStaticPaths`, meaning we need to rename nodes outside of the collection upon which we're currently acting.
301+
// it means we potentially need to rename something *not* already named `getServerSideProps` or `getStaticProps`,
302+
// meaning we need to rename nodes outside of the collection upon which we're currently acting.
303303
if (ExportSpecifier.check(parent)) {
304304
if (parent.exported.name !== parent.local?.name && node === parent.exported) {
305305
const currentLocalName = parent.local?.name || '';

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
* For `getInitialProps` we create a virtual proxy-module that re-exports all the exports and default exports of the
1110
* original file and wraps `getInitialProps`. We do this since it allows us to very generically wrap `getInitialProps`
@@ -34,7 +33,6 @@ import type { LoaderThis } from './types';
3433
const DATA_FETCHING_FUNCTIONS = {
3534
getServerSideProps: { placeholder: '__ORIG_GSSP__', alias: '' },
3635
getStaticProps: { placeholder: '__ORIG_GSPROPS__', alias: '' },
37-
getStaticPaths: { placeholder: '__ORIG_GSPATHS__', alias: '' },
3836
};
3937

4038
type LoaderOptions = {
@@ -102,7 +100,7 @@ function wrapFunctions(userCode: string, templateCode: string, filepath: string)
102100
}
103101

104102
/**
105-
* Wrap `getStaticPaths`, `getStaticProps`, and `getServerSideProps` (if they exist) in the given page code
103+
* Wrap `getStaticProps` and `getServerSideProps` (if they exist) in the given page code
106104
*/
107105
export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>, userCode: string): string {
108106
// For now this loader only works for ESM code

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,
@@ -30,7 +25,3 @@ export const getStaticProps =
3025
typeof __ORIG_GSPROPS__ === 'function'
3126
? ServerSideSentryNextjsSDK.withSentryGetStaticProps(__ORIG_GSPROPS__)
3227
: __ORIG_GSPROPS__;
33-
export const getStaticPaths =
34-
typeof __ORIG_GSPATHS__ === 'function'
35-
? ServerSideSentryNextjsSDK.withSentryGetStaticPaths(__ORIG_GSPATHS__)
36-
: __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,4 +1,3 @@
1-
export { withSentryGetStaticPaths } from './withSentryGetStaticPaths';
21
export { withSentryGetStaticProps } from './withSentryGetStaticProps';
32
export { withSentryGetInitialProps } from './withSentryGetInitialProps';
43
export { withSentryGetServerSideProps } from './withSentryGetServerSideProps';

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

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

15-
type Paths = { [key: string]: string | string[] };
1612
type Props = { [key: string]: unknown };
1713

18-
export type GSPaths = {
19-
fn: GetStaticPaths;
20-
wrappedFn: GetStaticPaths;
21-
context: GetStaticPathsContext;
22-
result: GetStaticPathsResult<Paths>;
23-
};
24-
2514
export type GSProps = {
2615
fn: GetStaticProps;
2716
wrappedFn: GetStaticProps;
@@ -43,4 +32,4 @@ export type GIProps = {
4332
result: unknown;
4433
};
4534

46-
export type DataFetchingFunction = GSPaths | GSProps | GSSP | GIProps;
35+
export type DataFetchingFunction = GSProps | GSSP | GIProps;

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-6
Original file line numberDiff line numberDiff line change
@@ -125,12 +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 {
129-
withSentryGetServerSideProps,
130-
withSentryGetStaticProps,
131-
withSentryGetStaticPaths,
132-
withSentryGetInitialProps,
133-
} from './config/wrappers';
128+
export { withSentryGetServerSideProps, withSentryGetStaticProps, withSentryGetInitialProps } from './config/wrappers';
134129
export { withSentry } from './utils/withSentry';
135130

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

0 commit comments

Comments
 (0)