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
3c985b02
Commit
3c985b02
authored
Oct 07, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Cache Components] do not cache request API promises in dev/request
parent
e0f676b6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
26 deletions
+101
-26
cookies.ts
packages/next/src/server/request/cookies.ts
+23
-7
headers.ts
packages/next/src/server/request/headers.ts
+23
-7
params.ts
packages/next/src/server/request/params.ts
+29
-6
search-params.ts
packages/next/src/server/request/search-params.ts
+26
-6
No files found.
packages/next/src/server/request/cookies.ts
View file @
3c985b02
...
...
@@ -171,6 +171,11 @@ function makeHangingCookies(
function
makeUntrackedCookies
(
underlyingCookies
:
ReadonlyRequestCookies
):
Promise
<
ReadonlyRequestCookies
>
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
Promise
.
resolve
(
underlyingCookies
)
}
const
cachedCookies
=
CachedCookies
.
get
(
underlyingCookies
)
if
(
cachedCookies
)
{
return
cachedCookies
...
...
@@ -186,14 +191,29 @@ function makeUntrackedCookiesWithDevWarnings(
underlyingCookies
:
ReadonlyRequestCookies
,
route
?:
string
):
Promise
<
ReadonlyRequestCookies
>
{
const
cachedCookies
=
CachedCookies
.
get
(
underlyingCookies
)
if
(
cachedCookies
)
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
makeUntrackedCookiesWithDevWarningsImpl
(
underlyingCookies
,
route
)
}
else
{
let
cachedCookies
=
CachedCookies
.
get
(
underlyingCookies
)
if
(
!
cachedCookies
)
{
cachedCookies
=
makeUntrackedCookiesWithDevWarningsImpl
(
underlyingCookies
,
route
)
CachedCookies
.
set
(
underlyingCookies
,
cachedCookies
)
}
return
cachedCookies
}
}
function
makeUntrackedCookiesWithDevWarningsImpl
(
underlyingCookies
:
ReadonlyRequestCookies
,
route
?:
string
):
Promise
<
ReadonlyRequestCookies
>
{
const
promise
=
makeDevtoolsIOAwarePromise
(
underlyingCookies
)
const
proxiedPromise
=
new
Proxy
(
promise
,
{
return
new
Proxy
(
promise
,
{
get
(
target
,
prop
,
receiver
)
{
switch
(
prop
)
{
case
Symbol
.
iterator
:
{
...
...
@@ -219,10 +239,6 @@ function makeUntrackedCookiesWithDevWarnings(
return
ReflectAdapter
.
get
(
target
,
prop
,
receiver
)
},
})
CachedCookies
.
set
(
underlyingCookies
,
proxiedPromise
)
return
proxiedPromise
}
const
warnForSyncAccess
=
createDedupedByCallsiteServerErrorLoggerDev
(
...
...
packages/next/src/server/request/headers.ts
View file @
3c985b02
...
...
@@ -180,6 +180,11 @@ function makeHangingHeaders(
function
makeUntrackedHeaders
(
underlyingHeaders
:
ReadonlyHeaders
):
Promise
<
ReadonlyHeaders
>
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
Promise
.
resolve
(
underlyingHeaders
)
}
const
cachedHeaders
=
CachedHeaders
.
get
(
underlyingHeaders
)
if
(
cachedHeaders
)
{
return
cachedHeaders
...
...
@@ -195,14 +200,29 @@ function makeUntrackedHeadersWithDevWarnings(
underlyingHeaders
:
ReadonlyHeaders
,
route
?:
string
):
Promise
<
ReadonlyHeaders
>
{
const
cachedHeaders
=
CachedHeaders
.
get
(
underlyingHeaders
)
if
(
cachedHeaders
)
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
makeUntrackedHeadersWithDevWarningsImpl
(
underlyingHeaders
,
route
)
}
else
{
let
cachedHeaders
=
CachedHeaders
.
get
(
underlyingHeaders
)
if
(
!
cachedHeaders
)
{
cachedHeaders
=
makeUntrackedHeadersWithDevWarningsImpl
(
underlyingHeaders
,
route
)
CachedHeaders
.
set
(
underlyingHeaders
,
cachedHeaders
)
}
return
cachedHeaders
}
}
function
makeUntrackedHeadersWithDevWarningsImpl
(
underlyingHeaders
:
ReadonlyHeaders
,
route
?:
string
):
Promise
<
ReadonlyHeaders
>
{
const
promise
=
makeDevtoolsIOAwarePromise
(
underlyingHeaders
)
const
proxiedPromise
=
new
Proxy
(
promise
,
{
return
new
Proxy
(
promise
,
{
get
(
target
,
prop
,
receiver
)
{
switch
(
prop
)
{
case
Symbol
.
iterator
:
{
...
...
@@ -230,10 +250,6 @@ function makeUntrackedHeadersWithDevWarnings(
return
ReflectAdapter
.
get
(
target
,
prop
,
receiver
)
},
})
CachedHeaders
.
set
(
underlyingHeaders
,
proxiedPromise
)
return
proxiedPromise
}
const
warnForSyncAccess
=
createDedupedByCallsiteServerErrorLoggerDev
(
...
...
packages/next/src/server/request/params.ts
View file @
3c985b02
...
...
@@ -431,6 +431,11 @@ function makeErroringParams(
}
function
makeUntrackedParams
(
underlyingParams
:
Params
):
Promise
<
Params
>
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
Promise
.
resolve
(
underlyingParams
)
}
const
cachedParams
=
CachedParams
.
get
(
underlyingParams
)
if
(
cachedParams
)
{
return
cachedParams
...
...
@@ -447,11 +452,32 @@ function makeDynamicallyTrackedParamsWithDevWarnings(
hasFallbackParams
:
boolean
,
store
:
WorkStore
):
Promise
<
Params
>
{
const
cachedParams
=
CachedParams
.
get
(
underlyingParams
)
if
(
cachedParams
)
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
makeDynamicallyTrackedParamsWithDevWarningsImpl
(
underlyingParams
,
hasFallbackParams
,
store
)
}
else
{
let
cachedParams
=
CachedParams
.
get
(
underlyingParams
)
if
(
!
cachedParams
)
{
cachedParams
=
makeDynamicallyTrackedParamsWithDevWarningsImpl
(
underlyingParams
,
hasFallbackParams
,
store
)
CachedParams
.
set
(
underlyingParams
,
cachedParams
)
}
return
cachedParams
}
}
function
makeDynamicallyTrackedParamsWithDevWarningsImpl
(
underlyingParams
:
Params
,
hasFallbackParams
:
boolean
,
store
:
WorkStore
):
Promise
<
Params
>
{
// We don't use makeResolvedReactPromise here because params
// supports copying with spread and we don't want to unnecessarily
// instrument the promise with spreadable properties of ReactPromise.
...
...
@@ -472,7 +498,7 @@ function makeDynamicallyTrackedParamsWithDevWarnings(
}
})
const
proxiedPromise
=
new
Proxy
(
promise
,
{
return
new
Proxy
(
promise
,
{
get
(
target
,
prop
,
receiver
)
{
if
(
typeof
prop
===
'string'
)
{
if
(
...
...
@@ -497,9 +523,6 @@ function makeDynamicallyTrackedParamsWithDevWarnings(
return
Reflect
.
ownKeys
(
target
)
},
})
CachedParams
.
set
(
underlyingParams
,
proxiedPromise
)
return
proxiedPromise
}
const
warnForSyncAccess
=
createDedupedByCallsiteServerErrorLoggerDev
(
...
...
packages/next/src/server/request/search-params.ts
View file @
3c985b02
...
...
@@ -358,6 +358,11 @@ export function makeErroringSearchParamsForUseCache(
function
makeUntrackedSearchParams
(
underlyingSearchParams
:
SearchParams
):
Promise
<
SearchParams
>
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
Promise
.
resolve
(
underlyingSearchParams
)
}
const
cachedSearchParams
=
CachedSearchParams
.
get
(
underlyingSearchParams
)
if
(
cachedSearchParams
)
{
return
cachedSearchParams
...
...
@@ -373,11 +378,29 @@ function makeUntrackedSearchParamsWithDevWarnings(
underlyingSearchParams
:
SearchParams
,
store
:
WorkStore
):
Promise
<
SearchParams
>
{
const
cachedSearchParams
=
CachedSearchParams
.
get
(
underlyingSearchParams
)
if
(
cachedSearchParams
)
{
// If CC is enabled, don't cache the promise.
if
(
process
.
env
.
__NEXT_CACHE_COMPONENTS
)
{
return
makeUntrackedSearchParamsWithDevWarningsImpl
(
underlyingSearchParams
,
store
)
}
else
{
let
cachedSearchParams
=
CachedSearchParams
.
get
(
underlyingSearchParams
)
if
(
!
cachedSearchParams
)
{
cachedSearchParams
=
makeUntrackedSearchParamsWithDevWarningsImpl
(
underlyingSearchParams
,
store
)
CachedSearchParams
.
set
(
underlyingSearchParams
,
cachedSearchParams
)
}
return
cachedSearchParams
}
}
function
makeUntrackedSearchParamsWithDevWarningsImpl
(
underlyingSearchParams
:
SearchParams
,
store
:
WorkStore
):
Promise
<
SearchParams
>
{
// Track which properties we should warn for.
const
proxiedProperties
=
new
Set
<
string
>
()
...
...
@@ -446,7 +469,7 @@ function makeUntrackedSearchParamsWithDevWarnings(
}
})
const
proxiedPromise
=
new
Proxy
(
promise
,
{
return
new
Proxy
(
promise
,
{
get
(
target
,
prop
,
receiver
)
{
if
(
prop
===
'then'
&&
store
.
dynamicShouldError
)
{
const
expression
=
'`searchParams.then`'
...
...
@@ -499,9 +522,6 @@ function makeUntrackedSearchParamsWithDevWarnings(
return
Reflect
.
ownKeys
(
target
)
},
})
CachedSearchParams
.
set
(
underlyingSearchParams
,
proxiedPromise
)
return
proxiedPromise
}
const
warnForSyncAccess
=
createDedupedByCallsiteServerErrorLoggerDev
(
...
...
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