Skip to content

Commit 4c3c3ce

Browse files
author
Luca Forstner
committed
Add comment explaining wht proxying is
1 parent 3ccbe10 commit 4c3c3ce

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ export default function wrapDataFetchersLoader(this: LoaderThis<LoaderOptions>,
113113
// We know one or the other will be defined, depending on the version of webpack being used
114114
const { projectDir } = 'getOptions' in this ? this.getOptions() : this.query;
115115

116-
// Proxy the processed file
116+
// In the following branch we will proxy the user's file. This means we return code (basically an entirely new file)
117+
// that re - exports all the user file's originial export, but with a "sentry-proxy-loader" query in the module
118+
// string.
119+
// This looks like the following: `export { a, b, c } from "[imagine userfile path here]?sentry-proxy-loader";`
120+
// Additionally, in this proxy file we import the userfile's default export, wrap `getInitialProps` on that default
121+
// export, and re -export the now modified default export as default.
122+
// Webpack will resolve the module with the "sentry-proxy-loader" query to the original file, but will give us access
123+
// to the query via`this.resourceQuery`. If we see that `this.resourceQuery` includes includes "sentry-proxy-loader"
124+
// we know we're in a proxied file and do not need to proxy again.
125+
117126
if (!this.resourceQuery.includes('sentry-proxy-loader')) {
118127
const ast = makeAST(userCode, true); // is there a reason to ever parse without typescript?
119128

0 commit comments

Comments
 (0)