Skip to content

Conversation

@lforst
Copy link
Contributor

@lforst lforst commented Jan 25, 2023

Ref: #6726

This PR injects the Next.js SDK into serverside app directory bundles, allowing users to call the Sentry SDK in server components.

@lforst lforst marked this pull request as ready for review January 25, 2023 10:32
@lforst lforst requested review from AbhiPrasad and mydea January 25, 2023 10:32
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

feels... brittle idk. But I guess the next webpack entry code has always been like that.

loader: path.resolve(__dirname, 'loaders', 'sdkMultiplexerLoader.js'),
options: {
importTarget: buildContext.nextRuntime === 'edge' ? './edge' : './client',
importTarget: { browser: './client', node: './server', edge: './edge' }[runtime],
Copy link
Member

Choose a reason for hiding this comment

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

l: Let's move this object into it's own const variable?

// User-specified pages to skip. (Note: For ease of use, `excludeServerRoutes` is specified in terms of routes,
// which don't have the `pages` prefix.)
const entryPointRoute = entryPointName.replace(/^pages/, '');
if (stringMatchesSomePattern(entryPointRoute, excludeServerRoutes, true)) {
Copy link
Member

Choose a reason for hiding this comment

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

l: can we just do

Suggested change
if (stringMatchesSomePattern(entryPointRoute, excludeServerRoutes, true)) {
return !stringMatchesSomePattern(entryPointRoute, excludeServerRoutes, true)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol yeah - the classic

const isomorphicValues = {
// `rewritesTunnel` set by the user in Next.js config
__sentryRewritesTunnelPath__: userSentryOptions.tunnelRoute,
SENTRY_RELEASE: { id: getSentryRelease(buildContext.buildId) },
Copy link
Member

Choose a reason for hiding this comment

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

l: can we move the The webpack plugin's release injection breaks the app directory comment down here?

});

it('injects user config file into `_app` in client bundle but not in server bundle', async () => {
it('injects user config file into `_app` in server bundle but not in client bundle', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

why did this condition flip?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It basically doesn't matter where we inject what. To clean things up a bit I decided we should inject the server SDK in the pages/_app entrypoint and the client SDK to the main and app-main entrypoints.

I assume this test just verified that we do not accidentally mess this up.

@lforst
Copy link
Contributor Author

lforst commented Jan 25, 2023

feels... brittle idk. But I guess the next webpack entry code has always been like that.

Absolutely. It is horrible but out of the 100 things I've tried, this was the only one that worked reliably...

@lforst lforst self-assigned this Jan 25, 2023
@lforst lforst merged commit 77de64e into master Jan 26, 2023
@lforst lforst deleted the lforst-inject-sentry-in-server-app-dir branch January 26, 2023 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants