Skip to content

Commit a834f7a

Browse files
Luca ForstnerAbhiPrasad
authored andcommitted
explain
1 parent b4c72c9 commit a834f7a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/nextjs/src/config/templates/serverComponentWrapperTemplate.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ const serverComponent = serverComponentModule.default;
2727

2828
let wrappedServerComponent;
2929
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.
3133
wrappedServerComponent = new Proxy(serverComponent, {
3234
apply: (originalFunction, thisArg, args) => {
3335
let sentryTraceHeader: string | undefined = undefined;
3436
let baggageHeader: string | undefined = undefined;
3537

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.
3640
if (process.env.NEXT_PHASE !== 'phase-production-build') {
3741
const headersList = headers();
3842
sentryTraceHeader = headersList.get('sentry-trace');

0 commit comments

Comments
 (0)