Skip to content

Commit 3ccbe10

Browse files
author
Luca Forstner
committed
Add comments clarifying why getInitialProps wrapper is imported directly
1 parent 4c97ee9 commit 3ccbe10

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>,
128128
}
129129

130130
if (hasDefaultExport(ast)) {
131+
// We don't import the `withSentryGetInitialProps` wrapper from `@sentry/nextjs` since `getInitialProps` can run
132+
// on both the server and the client and we don't want to have side effects from the server SDK on the client and
133+
// vice versa. By importing the loader directly we avoid the side effects.
131134
outputFileContent += `
132135
import { default as _sentry_default } from "${this.resourcePath}?sentry-proxy-loader";
133136
import { withSentryGetInitialProps } from "@sentry/nextjs/build/esm/config/wrappers";

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ export { withSentryGetStaticPaths } from './withSentryGetStaticPaths';
22
export { withSentryGetStaticProps } from './withSentryGetStaticProps';
33
export { withSentryGetInitialProps } from './withSentryGetInitialProps';
44
export { withSentryGetServerSideProps } from './withSentryGetServerSideProps';
5+
6+
// Disclaimer: Keep this file side-effect free. If you have to intruduce a side-effect, make sure it can run on the
7+
// browser and on the server. Reason: Our `getInitialProps` wrapper imports this file and `getInitialProps` might run on
8+
// the browser and / or on the server.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { GIProps } from './types';
22

3+
// Disclaimer: Keep this file side-effect free. If you have to intruduce a side-effect, make sure it can run on the
4+
// browser and on the server. Reason: This `getInitialProps` wrapper imports this file and `getInitialProps` might run on
5+
// the browser and / or on the server.
6+
37
/**
48
* Create a wrapped version of the user's exported `getInitialProps` function
59
*

0 commit comments

Comments
 (0)