You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #60645, dynamic access tracking was refactored but we erroneously
stopped tracking dynamic access in route handlers. Request proxying, as
well as tracking segment level configs (such as `export const dynamic =
'force-dynamic'`), were only enabled during static generation. This was
an unintended breaking change that consequently caused dynamic access to
not properly bail from data cache in various circumstances.
This adds some more rigorous testing for route handlers, as this seems
to be a fairly large gap in our fetch cache testing currently.
This PR is easiest to review with [whitespace
disabled](https://github.com/vercel/next.js/pull/66446/files?w=1).
Copy file name to clipboardExpand all lines: packages/next/src/server/app-render/dynamic-rendering.ts
+1-1
Original file line number
Diff line number
Diff line change
@@ -146,7 +146,7 @@ export function trackDynamicDataAccessed(
146
146
if(store.isStaticGeneration){
147
147
// We aren't prerendering but we are generating a static page. We need to bail out of static generation
148
148
consterr=newDynamicServerError(
149
-
`Route ${pathname} couldn't be rendered statically because it used ${expression}. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
149
+
`Route ${pathname} couldn't be rendered statically because it used \`${expression}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
`Route ${target.nextUrl.pathname} couldn't be rendered statically because it accessed \`request.${prop}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
690
-
)
691
-
case'clone':
692
-
return(
693
-
target[requestCloneSymbol]||
694
-
(target[requestCloneSymbol]=()=>
695
-
newProxy(
696
-
// This is vaguely unsafe but it's required since NextRequest does not implement
697
-
// clone. The reason we might expect this to work in this context is the Proxy will
698
-
// respond with static-amenable values anyway somewhat restoring the interface.
699
-
// @TODO we need to rethink NextRequest and NextURL because they are not sufficientlly
700
-
// sophisticated to adequately represent themselves in all contexts. A better approach is
701
-
// to probably embed the static generation logic into the class itself removing the need
// We don't need to proxy set because all the properties we proxy are ready only
716
-
// and will be ignored
717
-
}
676
+
case'clone':
677
+
return(
678
+
target[urlCloneSymbol]||
679
+
(target[urlCloneSymbol]=()=>
680
+
newProxy(target.clone(),nextUrlHandlers))
681
+
)
682
+
default:
683
+
constresult=Reflect.get(target,prop,receiver)
684
+
if(typeofresult==='function'){
685
+
returnresult.bind(target)
686
+
}
687
+
returnresult
688
+
}
689
+
},
690
+
}
718
691
719
-
conststaticGenerationNextUrlHandlers={
720
-
get(
721
-
target: NextURL&UrlSymbolTarget,
722
-
prop: string|symbol,
723
-
receiver: any
724
-
): unknown{
725
-
switch(prop){
726
-
case'search':
727
-
case'searchParams':
728
-
case'url':
729
-
case'href':
730
-
case'toJSON':
731
-
case'toString':
732
-
case'origin':
733
-
thrownewDynamicServerError(
734
-
`Route ${target.pathname} couldn't be rendered statically because it accessed \`nextUrl.${prop}\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
0 commit comments