Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
0770f285
Unverified
Commit
0770f285
authored
Aug 08, 2026
by
David Alexandru Ilie
Committed by
GitHub
Aug 08, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop app route prerenders after caught request access
parent
a6913835
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
module.ts
packages/next/src/server/route-modules/app-route/module.ts
+5
-2
route.ts
...r/cache-components/app/routes/caught-dynamic-url/route.ts
+20
-0
cache-components.routes.test.ts
.../app-dir/cache-components/cache-components.routes.test.ts
+16
-0
No files found.
packages/next/src/server/route-modules/app-route/module.ts
View file @
0770f285
...
...
@@ -637,10 +637,13 @@ export class AppRouteRouteModule extends RouteModule<
trackPendingModules
(
cacheSignal
)
await
cacheSignal
.
cacheReady
()
if
(
prospectiveRenderIsDynamic
)
{
// The handler may catch the prerender interruption and resolve
// normally, but dynamic tracking still records the request access.
const
dynamicReason
=
getFirstDynamicReason
(
dynamicTracking
)
if
(
prospectiveRenderIsDynamic
||
dynamicReason
)
{
// the route handler called an API which is always dynamic
// there is no need to try again
const
dynamicReason
=
getFirstDynamicReason
(
dynamicTracking
)
if
(
dynamicReason
)
{
throw
new
DynamicServerError
(
`Route
${
workStore
.
route
}
couldn't be rendered statically because it used \`
${
dynamicReason
}
\`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error`
...
...
test/e2e/app-dir/cache-components/app/routes/caught-dynamic-url/route.ts
0 → 100644
View file @
0770f285
import
type
{
NextRequest
}
from
'next/server'
import
{
getSentinelValue
}
from
'../../getSentinelValue'
export
async
function
GET
(
request
:
NextRequest
)
{
let
search
=
''
try
{
search
=
request
.
nextUrl
.
search
}
catch
{
console
.
log
(
'caught dynamic URL access'
)
}
return
new
Response
(
JSON
.
stringify
({
value
:
getSentinelValue
(),
search
,
})
)
}
test/e2e/app-dir/cache-components/cache-components.routes.test.ts
View file @
0770f285
...
...
@@ -50,6 +50,22 @@ describe('cache-components', () => {
expect
(
json
.
search
).
toEqual
(
'?foo=bar'
)
})
it
(
'should stop the prospective render when a dynamic API error is caught'
,
async
()
=>
{
if
(
!
isNextDev
)
{
const
prospectiveRenderLogs
=
next
.
cliOutput
.
split
(
'
\
n'
)
.
filter
((
line
)
=>
line
.
includes
(
'caught dynamic URL access'
))
expect
(
prospectiveRenderLogs
).
toHaveLength
(
1
)
}
const
str
=
await
next
.
render
(
'/routes/caught-dynamic-url?foo=bar'
,
{})
const
json
=
JSON
.
parse
(
str
)
expect
(
json
.
value
).
toEqual
(
'at runtime'
)
expect
(
json
.
search
).
toEqual
(
'?foo=bar'
)
})
it
(
'should prerender GET route handlers that have entirely cached io (fetches)'
,
async
()
=>
{
let
str
=
await
next
.
render
(
'/routes/fetch-cached'
,
{})
let
json
=
JSON
.
parse
(
str
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment