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
73fc64ef
Commit
73fc64ef
authored
Mar 11, 2026
by
Zack Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix empty partial-fallback shells in memory cache
parent
a18ae7d7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
13 deletions
+43
-13
memory-cache.external.test.ts
...erver/lib/incremental-cache/memory-cache.external.test.ts
+24
-0
memory-cache.external.ts
...src/server/lib/incremental-cache/memory-cache.external.ts
+19
-13
No files found.
packages/next/src/server/lib/incremental-cache/memory-cache.external.test.ts
0 → 100644
View file @
73fc64ef
import
type
{
CacheHandlerValue
}
from
'.'
import
{
CachedRouteKind
}
from
'../../response-cache/types'
import
{
getMemoryCache
}
from
'./memory-cache.external'
describe
(
'getMemoryCache'
,
()
=>
{
it
(
'stores app-page entries with an empty html shell'
,
()
=>
{
const
cache
=
getMemoryCache
(
1024
)
const
entry
:
CacheHandlerValue
=
{
lastModified
:
Date
.
now
(),
value
:
{
kind
:
CachedRouteKind
.
APP_PAGE
,
html
:
''
,
rscData
:
undefined
,
status
:
200
,
postponed
:
'postponed-state'
,
headers
:
undefined
,
segmentData
:
undefined
,
},
}
expect
(()
=>
cache
.
set
(
'/shell'
,
entry
)).
not
.
toThrow
()
expect
(
cache
.
get
(
'/shell'
)).
toEqual
(
entry
)
})
})
packages/next/src/server/lib/incremental-cache/memory-cache.external.ts
View file @
73fc64ef
...
...
@@ -7,26 +7,32 @@ let memoryCache: LRUCache<CacheHandlerValue> | undefined
export
function
getMemoryCache
(
maxMemoryCacheSize
:
number
)
{
if
(
!
memoryCache
)
{
memoryCache
=
new
LRUCache
(
maxMemoryCacheSize
,
function
length
({
value
})
{
let
size
:
number
if
(
!
value
)
{
return
25
size
=
25
}
else
if
(
value
.
kind
===
CachedRouteKind
.
REDIRECT
)
{
return
JSON
.
stringify
(
value
.
props
).
length
size
=
JSON
.
stringify
(
value
.
props
).
length
}
else
if
(
value
.
kind
===
CachedRouteKind
.
IMAGE
)
{
throw
new
Error
(
'invariant image should not be incremental-cache'
)
}
else
if
(
value
.
kind
===
CachedRouteKind
.
FETCH
)
{
return
JSON
.
stringify
(
value
.
data
||
''
).
length
size
=
JSON
.
stringify
(
value
.
data
||
''
).
length
}
else
if
(
value
.
kind
===
CachedRouteKind
.
APP_ROUTE
)
{
return
value
.
body
.
length
size
=
value
.
body
.
length
}
else
{
// APP_PAGE and PAGES entries can legitimately have an empty HTML shell
// (for example, a generic partial-fallback shell backed entirely by
// postponed data). Keep those entries cacheable by enforcing the
// minimum non-zero size expected by LRUCache.
size
=
value
.
html
.
length
+
(
JSON
.
stringify
(
value
.
kind
===
CachedRouteKind
.
APP_PAGE
?
value
.
rscData
:
value
.
pageData
)?.
length
||
0
)
}
// rough estimate of size of cache value
return
(
value
.
html
.
length
+
(
JSON
.
stringify
(
value
.
kind
===
CachedRouteKind
.
APP_PAGE
?
value
.
rscData
:
value
.
pageData
)?.
length
||
0
)
)
return
Math
.
max
(
size
,
1
)
})
}
...
...
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