Skip to content

Commit dfd66b4

Browse files
committed
test successive cache reads
1 parent fba4609 commit dfd66b4

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

test/development/app-dir/cache-components-dev-warmup/app/data-fetching.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,39 @@ export async function CachedData({
3232
)
3333
}
3434

35+
export async function SuccessiveCachedData({
36+
label,
37+
cacheKey,
38+
}: {
39+
label: string
40+
cacheKey: string
41+
}) {
42+
// This components tests if we correctly handle the case where resolving a cache
43+
// reveals another cache in the children. When we're filling caches, we should fill both.
44+
const data1 = await getCachedData(`${cacheKey}-successive-1`)
45+
return (
46+
<dl>
47+
<dt>Cached Data (successive reads)</dt>
48+
<dd>{data1}</dd>
49+
<dd>
50+
<SuccessiveCachedDataChild label={label} cacheKey={cacheKey} />
51+
</dd>
52+
</dl>
53+
)
54+
}
55+
56+
async function SuccessiveCachedDataChild({
57+
label,
58+
cacheKey,
59+
}: {
60+
label: string
61+
cacheKey: string
62+
}) {
63+
const data2 = await getCachedData(`${cacheKey}-successive-2`)
64+
console.log(`after successive cache reads - ${label}`)
65+
return <>{data2}</>
66+
}
67+
3568
export async function CachedFetch({
3669
label,
3770
cacheKey,

test/development/app-dir/cache-components-dev-warmup/app/private-cache/data-fetching.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,39 @@ export async function PrivateCachedData({
1515
)
1616
}
1717

18+
export async function SuccessivePrivateCachedData({
19+
label,
20+
cacheKey,
21+
}: {
22+
label: string
23+
cacheKey: string
24+
}) {
25+
// This components tests if we correctly handle the case where resolving a cache
26+
// reveals another cache in the children. When we're filling caches, we should fill both.
27+
const data1 = await getPrivateCachedData(`${cacheKey}-successive-1`)
28+
return (
29+
<dl>
30+
<dt>Private Cached Data (successive reads)</dt>
31+
<dd>{data1}</dd>
32+
<dd>
33+
<SuccessivePrivateCachedDataChild label={label} cacheKey={cacheKey} />
34+
</dd>
35+
</dl>
36+
)
37+
}
38+
39+
async function SuccessivePrivateCachedDataChild({
40+
label,
41+
cacheKey,
42+
}: {
43+
label: string
44+
cacheKey: string
45+
}) {
46+
const data2 = await getPrivateCachedData(`${cacheKey}-successive-2`)
47+
console.log(`after successive private cache reads - ${label}`)
48+
return <>{data2}</>
49+
}
50+
1851
async function getPrivateCachedData(_key: string) {
1952
'use cache: private'
2053
await new Promise((r) => setTimeout(r))

test/development/app-dir/cache-components-dev-warmup/app/private-cache/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Suspense } from 'react'
22
import { CachedData, UncachedFetch } from '../data-fetching'
3-
import { PrivateCachedData } from './data-fetching'
3+
import { PrivateCachedData, SuccessivePrivateCachedData } from './data-fetching'
44

55
const CACHE_KEY = '/private-cache/__PAGE__'
66

@@ -15,6 +15,10 @@ export default async function Page() {
1515
<PrivateCachedData label="page" cacheKey={CACHE_KEY} />
1616
</Suspense>
1717

18+
<Suspense fallback="Loading two successive private caches...">
19+
<SuccessivePrivateCachedData label="page" cacheKey={CACHE_KEY} />
20+
</Suspense>
21+
1822
<Suspense fallback="Loading uncached fetch...">
1923
<UncachedFetch label="page" cacheKey={CACHE_KEY} />
2024
</Suspense>

test/development/app-dir/cache-components-dev-warmup/app/simple/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Suspense } from 'react'
2-
import { CachedData, CachedFetch, UncachedFetch } from '../data-fetching'
2+
import {
3+
CachedData,
4+
CachedFetch,
5+
SuccessiveCachedData,
6+
UncachedFetch,
7+
} from '../data-fetching'
38

49
const CACHE_KEY = __dirname + '/__PAGE__'
510

@@ -16,6 +21,7 @@ export default async function Page() {
1621
</p>
1722

1823
<CachedData label="page" cacheKey={CACHE_KEY} />
24+
<SuccessiveCachedData label="page" cacheKey={CACHE_KEY} />
1925

2026
<CachedFetch label="page" cacheKey={CACHE_KEY} />
2127

test/development/app-dir/cache-components-dev-warmup/cache-components.dev-warmup.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('cache-components-dev-warmup', () => {
4747
const logs = await browser.log()
4848
assertLog(logs, 'after cache read - layout', 'Prerender')
4949
assertLog(logs, 'after cache read - page', 'Prerender')
50+
assertLog(logs, 'after successive cache reads - page', 'Prerender')
5051
assertLog(logs, 'after cached fetch - layout', 'Prerender')
5152
assertLog(logs, 'after cached fetch - page', 'Prerender')
5253

@@ -83,6 +84,7 @@ describe('cache-components-dev-warmup', () => {
8384
// so they shouldn't resolve in the static stage.
8485
assertLog(logs, 'after private cache read - page', 'Server') // TODO: 'Runtime Prerender'
8586
assertLog(logs, 'after private cache read - layout', 'Server') // TODO: 'Runtime Prerender'
87+
assertLog(logs, 'after successive private cache reads - page', 'Server') // TODO: 'Runtime Prerender'
8688

8789
assertLog(logs, 'after uncached fetch - layout', 'Server')
8890
assertLog(logs, 'after uncached fetch - page', 'Server')

0 commit comments

Comments
 (0)