Skip to content
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

feat(nextjs): Add auto-wrapping for server components #6953

Merged
merged 27 commits into from Feb 2, 2023

Conversation

lforst
Copy link
Member

@lforst lforst commented Jan 27, 2023

Ref: #6726

This PR adds a very basic wrapper for Next.js app directory server components that reports errors that occur. Additionally, this PR adds auto wrapping for that wrapper and a test to verify the auto wrapping.

I did some slight refactoring of the wrapping loader because it was becoming unwieldy with multiple different wrapping types.

Tests for app dir are broken atm so not adding any right now.

@@ -11,7 +11,7 @@ export default [
'src/client/index.ts',
'src/server/index.ts',
'src/edge/index.ts',
'src/config/webpack.ts',
'src/config/index.ts',
Copy link
Member Author

Choose a reason for hiding this comment

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

This was an oversight from before

@lforst lforst marked this pull request as ready for review January 27, 2023 15:29
@lforst lforst force-pushed the lforst-add-app-directory-component-wrappers branch from 5e9bb35 to fdf9300 Compare January 27, 2023 16:35
@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.91 KB (-0.01% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 61.72 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.59 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 55.02 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.32 KB (0%)
@sentry/browser - Webpack (minified) 66.48 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.35 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.64 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.82 KB (-0.01% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.12 KB (-0.01% 🔽)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.85 KB (-0.01% 🔽)
@sentry/replay - Webpack (gzipped + minified) 38.76 KB (0%)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 61.48 KB (0%)

@lforst lforst changed the base branch from master to develop February 1, 2023 09:28
@lforst lforst requested review from mydea and AbhiPrasad and removed request for mydea and AbhiPrasad February 1, 2023 10:44
*/
export function wrapAppDirComponentWithSentry<F extends (...args: any[]) => any>(appDirComponent: F): F {
// Even though users may define server components as async functions, for the client bundles
// Next.js will turn them into synchronous functionsf and it will transform any`await`s into instances of the`use`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Next.js will turn them into synchronous functionsf and it will transform any`await`s into instances of the`use`
// Next.js will turn them into synchronous functions and it will transform any `await`s into instances of the`use`

Ditto for the one below.

I don't like repeating this logic between server/edge, but I guess it's fine for now.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder what kind of spans we could get from here 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

We could probably get some nice ones but since async context is super funky here atm with the app dir we can't have only one transaction for all the server components and I would feel bad for creating individual transactions for each server component.

(We need to put in some more work here - I will create an issue to track everything that we still can improve)

loader: path.resolve(__dirname, 'loaders', 'wrappingLoader.js'),
options: {
...staticWrappingLoaderOptions,
wrappingTargetKind: 'middleware',
Copy link
Member

Choose a reason for hiding this comment

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

m: Ideally I would like to see some unit tests that show we are applying the correct wrappingTargetKind - this seems fragile and easy to regress on if we change the path test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added some in 9401d66

Thanks for holding me accountable to tests btw.

@lforst lforst merged commit 0ea7a86 into develop Feb 2, 2023
@lforst lforst deleted the lforst-add-app-directory-component-wrappers branch February 2, 2023 13:40
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.

None yet

2 participants