File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
packages/nextjs/src/config/templates Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,15 @@ if (typeof serverComponent === 'function') {
38
38
// If we call the headers function inside the build phase, Next.js will automatically mark the server component as
39
39
// dynamic(SSR) which we do not want in case the users have a static component.
40
40
if ( process . env . NEXT_PHASE !== 'phase-production-build' ) {
41
- const headersList = headers ( ) ;
42
- sentryTraceHeader = headersList . get ( 'sentry-trace' ) ;
43
- baggageHeader = headersList . get ( 'baggage' ) ;
41
+ // try/catch because calling headers() when a previously statically generated page is being revalidated causes a
42
+ // runtime error in next.js as switching a page from static to dynamic during runtime is not allowed
43
+ try {
44
+ const headersList = headers ( ) ;
45
+ sentryTraceHeader = headersList . get ( 'sentry-trace' ) ;
46
+ baggageHeader = headersList . get ( 'baggage' ) ;
47
+ } catch {
48
+ /** empty */
49
+ }
44
50
}
45
51
46
52
return Sentry . wrapServerComponentWithSentry ( originalFunction , {
You can’t perform that action at this time.
0 commit comments