Skip to content

Commit a111905

Browse files
author
Luca Forstner
authored
fix(nextjs): Inject client config into _app instead of main (#7009)
1 parent fd4db0d commit a111905

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,13 @@ function shouldAddSentryToEntryPoint(
473473
return entryPointName.startsWith('pages/');
474474
} else if (runtime === 'browser') {
475475
return (
476-
entryPointName === 'main' || // entrypoint for `/pages` pages
477-
entryPointName === 'main-app' // entrypoint for `/app` pages
476+
// entrypoint for `/pages` pages - this is included on all clientside pages
477+
// It's important that we inject the SDK into this file and not into 'main' because in 'main'
478+
// some important Next.js code (like the setup code for getCongig()) is located and some users
479+
// may need this code inside their Sentry configs
480+
entryPointName === 'pages/_app' ||
481+
// entrypoint for `/app` pages
482+
entryPointName === 'main-app'
478483
);
479484
} else {
480485
// User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,

packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('constructWebpackConfigFunction()', () => {
139139
);
140140
});
141141

142-
it('injects user config file into `_app` in server bundle but not in client bundle', async () => {
142+
it('injects user config file into `_app` in server bundle and in the client bundle', async () => {
143143
const finalServerWebpackConfig = await materializeFinalWebpackConfig({
144144
exportedNextConfig,
145145
incomingWebpackConfig: serverWebpackConfig,
@@ -158,7 +158,7 @@ describe('constructWebpackConfigFunction()', () => {
158158
);
159159
expect(finalClientWebpackConfig.entry).toEqual(
160160
expect.objectContaining({
161-
'pages/_app': expect.not.arrayContaining([clientConfigFilePath]),
161+
'pages/_app': expect.arrayContaining([clientConfigFilePath]),
162162
}),
163163
);
164164
});
@@ -233,9 +233,9 @@ describe('constructWebpackConfigFunction()', () => {
233233
});
234234

235235
expect(finalWebpackConfig.entry).toEqual({
236-
main: ['./sentry.client.config.js', './src/index.ts'],
236+
main: './src/index.ts',
237237
// only _app has config file injected
238-
'pages/_app': 'next-client-pages-loader?page=%2F_app',
238+
'pages/_app': ['./sentry.client.config.js', 'next-client-pages-loader?page=%2F_app'],
239239
'pages/_error': 'next-client-pages-loader?page=%2F_error',
240240
'pages/sniffTour': ['./node_modules/smellOVision/index.js', 'private-next-pages/sniffTour.js'],
241241
'pages/simulator/leaderboard': {

0 commit comments

Comments
 (0)