File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
packages/nextjs/src/config/templates Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,16 @@ const serverComponent = serverComponentModule.default;
27
27
28
28
let wrappedServerComponent ;
29
29
if ( typeof serverComponent === 'function' ) {
30
- // TODO: explain why this code needs to be in this file
30
+ // For some odd Next.js magic reason, `headers()` will not work if used inside `wrapServerComponentsWithSentry`.
31
+ // Current assumption is that Next.js applies some loader magic to userfiles, but not files in node_modules. This file
32
+ // is technically a userfile so it gets the loader magic applied.
31
33
wrappedServerComponent = new Proxy ( serverComponent , {
32
34
apply : ( originalFunction , thisArg , args ) => {
33
35
let sentryTraceHeader : string | undefined = undefined ;
34
36
let baggageHeader : string | undefined = undefined ;
35
37
38
+ // If we call the headers function inside the build phase, Next.js will automatically mark the server component as
39
+ // dynamic(SSR) which we do not want in case the users have a static component.
36
40
if ( process . env . NEXT_PHASE !== 'phase-production-build' ) {
37
41
const headersList = headers ( ) ;
38
42
sentryTraceHeader = headersList . get ( 'sentry-trace' ) ;
You can’t perform that action at this time.
0 commit comments