8000 fix(nextjs): Mark value injection loader result as uncacheable (#7870) · benjick/sentry-javascript@82763b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82763b7

Browse files
authored
fix(nextjs): Mark value injection loader result as uncacheable (getsentry#7870)
1 parent ee60f71 commit 82763b7

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed
Lines changed: 42 additions & 7 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,62 @@
11
import type webpack from 'webpack';
22

33
export type LoaderThis<Options> = {
4-
/** Path to the file being loaded */
4+
/**
5+
* Path to the file being loaded
6+
*
7+
* https://webpack.js.org/api/loaders/#thisresourcepath
8+
*/
59
resourcePath: string;
610

7-
/** Query at the end of resolved file name ("../some-folder/some-module?foobar" -> resourceQuery: "?foobar") */
11+
/**
12+
* Query at the end of resolved file name ("../some-folder/some-module?foobar" -> resourceQuery: "?foobar")
13+
*
14+
* https://webpack.js.org/api/loaders/#thisresourcequery
15+
*/
816
resourceQuery: string;
917

10-
// Function to add outside file used by loader to `watch` process
18+
/**
19+
* Function to add outside file used by loader to `watch` process
20+
*
21+
* https://webpack.js.org/api/loaders/#thisadddependency
22+
*/
1123
addDependency: (filepath: string) => void;
1224

13-
// Marks a loader as asynchronous
25+
/**
26+
* Marks a loader result as cacheable.
27+
*
28+
* https://webpack.js.org/api/loaders/#thiscacheable
29+
*/
30+
cacheable: (flag: boolean) => void;
31+
32+
/**
33+
* Marks a loader as asynchronous
34+
*
35+
* https://webpack.js.org/api/loaders/#thisasync
36+
*/
1437
async: webpack.loader.LoaderContext['async'];
1538

16-
// Return errors, code, and sourcemaps from an asynchronous loader
39+
/**
40+
* Return errors, code, and sourcemaps from an asynchronous loader
41+
*
42+
* https://webpack.js.org/api/loaders/#thiscallback
43+
*/
1744
callback: webpack.loader.LoaderContext['callback'];
1845
} & (
1946
| {
20-
// Loader options in Webpack 4
47+
/**
48+
* Loader options in Webpack 4
49+
*
50+
* https://webpack.js.org/api/loaders/#thisquery
51+
*/
2152
query: Options;
2253
}
2354
| {
24-
// Loader options in Webpack 5
55+
/**
56+
* Loader options in Webpack 5
57+
*
58+
* https://webpack.js.org/api/loaders/#thisgetoptionsschema
59+
*/
2560
getOptions: () => Options;
2661
}
2762
);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export default function valueInjectionLoader(this: LoaderThis<LoaderOptions>, us
1515
// We know one or the other will be defined, depending on the version of webpack being used
1616
const { values } = 'getOptions' in this ? this.getOptions() : this.query;
1717

18+
// We do not want to cache injected values across builds
19+
this.cacheable(false);
20+
1821
// Define some global proxy that works on server and on the browser.
1922
let injectedCode = 'var _sentryCollisionFreeGlobalObject = typeof window === "undefined" ? global : window;\n';
2023

packages/nextjs/src/config/webpack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ function addValueInjectionLoader(
855855
__sentryRewritesTunnelPath__: userSentryOptions.tunnelRoute,
856856

857857
// The webpack plugin's release injection breaks the `app` directory so we inject the release manually here instead.
858-
SENTRY_RELEASE: { id: getSentryRelease(buildContext.buildId) },
858+
// Having a release defined in dev-mode spams releases in Sentry so we only set one in non-dev mode
859+
SENTRY_RELEASE: buildContext.dev ? undefined : { id: getSentryRelease(buildContext.buildId) },
859860
};
860861

861862
const serverValues = {

0 commit comments

Comments
 (0)
0