Skip to content

fix(nextjs): Inject client config into _app instead of main #7009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,13 @@ function shouldAddSentryToEntryPoint(
return entryPointName.startsWith('pages/');
} else if (runtime === 'browser') {
return (
entryPointName === 'main' || // entrypoint for `/pages` pages
entryPointName === 'main-app' // entrypoint for `/app` pages
// entrypoint for `/pages` pages - this is included on all clientside pages
// It's important that we inject the SDK into this file and not into 'main' because in 'main'
// some important Next.js code (like the setup code for getCongig()) is located and some users

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a typo. getCongig() should be getConfig()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting us know! :D

// may need this code inside their Sentry configs
entryPointName === 'pages/_app' ||
// entrypoint for `/app` pages
entryPointName === 'main-app'
);
} else {
// User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('constructWebpackConfigFunction()', () => {
);
});

it('injects user config file into `_app` in server bundle but not in client bundle', async () => {
it('injects user config file into `_app` in server bundle and in the client bundle', async () => {
const finalServerWebpackConfig = await materializeFinalWebpackConfig({
exportedNextConfig,
incomingWebpackConfig: serverWebpackConfig,
Expand All @@ -158,7 +158,7 @@ describe('constructWebpackConfigFunction()', () => {
);
expect(finalClientWebpackConfig.entry).toEqual(
expect.objectContaining({
'pages/_app': expect.not.arrayContaining([clientConfigFilePath]),
'pages/_app': expect.arrayContaining([clientConfigFilePath]),
}),
);
});
Expand Down Expand Up @@ -233,9 +233,9 @@ describe('constructWebpackConfigFunction()', () => {
});

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