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
dfd66b4c
Commit
dfd66b4c
authored
Oct 09, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test successive cache reads
parent
fba4609b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
2 deletions
+80
-2
data-fetching.tsx
...app-dir/cache-components-dev-warmup/app/data-fetching.tsx
+33
-0
data-fetching.tsx
...components-dev-warmup/app/private-cache/data-fetching.tsx
+33
-0
page.tsx
...ir/cache-components-dev-warmup/app/private-cache/page.tsx
+5
-1
page.tsx
...t/app-dir/cache-components-dev-warmup/app/simple/page.tsx
+7
-1
cache-components.dev-warmup.test.ts
...components-dev-warmup/cache-components.dev-warmup.test.ts
+2
-0
No files found.
test/development/app-dir/cache-components-dev-warmup/app/data-fetching.tsx
View file @
dfd66b4c
...
@@ -32,6 +32,39 @@ export async function CachedData({
...
@@ -32,6 +32,39 @@ export async function CachedData({
)
)
}
}
export
async
function
SuccessiveCachedData
({
label
,
cacheKey
,
}:
{
label
:
string
cacheKey
:
string
})
{
// This components tests if we correctly handle the case where resolving a cache
// reveals another cache in the children. When we're filling caches, we should fill both.
const
data1
=
await
getCachedData
(
`
${
cacheKey
}
-successive-1`
)
return
(
<
dl
>
<
dt
>
Cached Data (successive reads)
</
dt
>
<
dd
>
{
data1
}
</
dd
>
<
dd
>
<
SuccessiveCachedDataChild
label=
{
label
}
cacheKey=
{
cacheKey
}
/>
</
dd
>
</
dl
>
)
}
async
function
SuccessiveCachedDataChild
({
label
,
cacheKey
,
}:
{
label
:
string
cacheKey
:
string
})
{
const
data2
=
await
getCachedData
(
`
${
cacheKey
}
-successive-2`
)
console
.
log
(
`after successive cache reads -
${
label
}
`
)
return
<>
{
data2
}
</>
}
export
async
function
CachedFetch
({
export
async
function
CachedFetch
({
label
,
label
,
cacheKey
,
cacheKey
,
...
...
test/development/app-dir/cache-components-dev-warmup/app/private-cache/data-fetching.tsx
View file @
dfd66b4c
...
@@ -15,6 +15,39 @@ export async function PrivateCachedData({
...
@@ -15,6 +15,39 @@ export async function PrivateCachedData({
)
)
}
}
export
async
function
SuccessivePrivateCachedData
({
label
,
cacheKey
,
}:
{
label
:
string
cacheKey
:
string
})
{
// This components tests if we correctly handle the case where resolving a cache
// reveals another cache in the children. When we're filling caches, we should fill both.
const
data1
=
await
getPrivateCachedData
(
`
${
cacheKey
}
-successive-1`
)
return
(
<
dl
>
<
dt
>
Private Cached Data (successive reads)
</
dt
>
<
dd
>
{
data1
}
</
dd
>
<
dd
>
<
SuccessivePrivateCachedDataChild
label=
{
label
}
cacheKey=
{
cacheKey
}
/>
</
dd
>
</
dl
>
)
}
async
function
SuccessivePrivateCachedDataChild
({
label
,
cacheKey
,
}:
{
label
:
string
cacheKey
:
string
})
{
const
data2
=
await
getPrivateCachedData
(
`
${
cacheKey
}
-successive-2`
)
console
.
log
(
`after successive private cache reads -
${
label
}
`
)
return
<>
{
data2
}
</>
}
async
function
getPrivateCachedData
(
_key
:
string
)
{
async
function
getPrivateCachedData
(
_key
:
string
)
{
'use cache: private'
'use cache: private'
await
new
Promise
((
r
)
=>
setTimeout
(
r
))
await
new
Promise
((
r
)
=>
setTimeout
(
r
))
...
...
test/development/app-dir/cache-components-dev-warmup/app/private-cache/page.tsx
View file @
dfd66b4c
import
{
Suspense
}
from
'react'
import
{
Suspense
}
from
'react'
import
{
CachedData
,
UncachedFetch
}
from
'../data-fetching'
import
{
CachedData
,
UncachedFetch
}
from
'../data-fetching'
import
{
PrivateCachedData
}
from
'./data-fetching'
import
{
PrivateCachedData
,
SuccessivePrivateCachedData
}
from
'./data-fetching'
const
CACHE_KEY
=
'/private-cache/__PAGE__'
const
CACHE_KEY
=
'/private-cache/__PAGE__'
...
@@ -15,6 +15,10 @@ export default async function Page() {
...
@@ -15,6 +15,10 @@ export default async function Page() {
<
PrivateCachedData
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
<
PrivateCachedData
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
</
Suspense
>
</
Suspense
>
<
Suspense
fallback=
"Loading two successive private caches..."
>
<
SuccessivePrivateCachedData
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
</
Suspense
>
<
Suspense
fallback=
"Loading uncached fetch..."
>
<
Suspense
fallback=
"Loading uncached fetch..."
>
<
UncachedFetch
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
<
UncachedFetch
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
</
Suspense
>
</
Suspense
>
...
...
test/development/app-dir/cache-components-dev-warmup/app/simple/page.tsx
View file @
dfd66b4c
import
{
Suspense
}
from
'react'
import
{
Suspense
}
from
'react'
import
{
CachedData
,
CachedFetch
,
UncachedFetch
}
from
'../data-fetching'
import
{
CachedData
,
CachedFetch
,
SuccessiveCachedData
,
UncachedFetch
,
}
from
'../data-fetching'
const
CACHE_KEY
=
__dirname
+
'/__PAGE__'
const
CACHE_KEY
=
__dirname
+
'/__PAGE__'
...
@@ -16,6 +21,7 @@ export default async function Page() {
...
@@ -16,6 +21,7 @@ export default async function Page() {
</
p
>
</
p
>
<
CachedData
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
<
CachedData
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
<
SuccessiveCachedData
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
<
CachedFetch
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
<
CachedFetch
label=
"page"
cacheKey=
{
CACHE_KEY
}
/>
...
...
test/development/app-dir/cache-components-dev-warmup/cache-components.dev-warmup.test.ts
View file @
dfd66b4c
...
@@ -47,6 +47,7 @@ describe('cache-components-dev-warmup', () => {
...
@@ -47,6 +47,7 @@ describe('cache-components-dev-warmup', () => {
const
logs
=
await
browser
.
log
()
const
logs
=
await
browser
.
log
()
assertLog
(
logs
,
'after cache read - layout'
,
'Prerender'
)
assertLog
(
logs
,
'after cache read - layout'
,
'Prerender'
)
assertLog
(
logs
,
'after cache read - page'
,
'Prerender'
)
assertLog
(
logs
,
'after cache read - page'
,
'Prerender'
)
assertLog
(
logs
,
'after successive cache reads - page'
,
'Prerender'
)
assertLog
(
logs
,
'after cached fetch - layout'
,
'Prerender'
)
assertLog
(
logs
,
'after cached fetch - layout'
,
'Prerender'
)
assertLog
(
logs
,
'after cached fetch - page'
,
'Prerender'
)
assertLog
(
logs
,
'after cached fetch - page'
,
'Prerender'
)
...
@@ -83,6 +84,7 @@ describe('cache-components-dev-warmup', () => {
...
@@ -83,6 +84,7 @@ describe('cache-components-dev-warmup', () => {
// so they shouldn't resolve in the static stage.
// so they shouldn't resolve in the static stage.
assertLog
(
logs
,
'after private cache read - page'
,
'Server'
)
// TODO: 'Runtime Prerender'
assertLog
(
logs
,
'after private cache read - page'
,
'Server'
)
// TODO: 'Runtime Prerender'
assertLog
(
logs
,
'after private cache read - layout'
,
'Server'
)
// TODO: 'Runtime Prerender'
assertLog
(
logs
,
'after private cache read - layout'
,
'Server'
)
// TODO: 'Runtime Prerender'
assertLog
(
logs
,
'after successive private cache reads - page'
,
'Server'
)
// TODO: 'Runtime Prerender'
assertLog
(
logs
,
'after uncached fetch - layout'
,
'Server'
)
assertLog
(
logs
,
'after uncached fetch - layout'
,
'Server'
)
assertLog
(
logs
,
'after uncached fetch - page'
,
'Server'
)
assertLog
(
logs
,
'after uncached fetch - page'
,
'Server'
)
...
...
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