Skip to content

Commit e1a4368

Browse files
lubieowocegnoff
authored andcommitted
tests
1 parent 63837aa commit e1a4368

File tree

33 files changed

+769
-227
lines changed

33 files changed

+769
-227
lines changed

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

Lines changed: 271 additions & 227 deletions
Large diffs are not rendered by default.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { cookies, headers } from 'next/headers'
2+
import { CachedData } from '../../data-fetching'
3+
import { connection } from 'next/server'
4+
import { Suspense } from 'react'
5+
6+
export const unstable_prefetch = { mode: 'runtime', samples: [{}] }
7+
8+
const CACHE_KEY = __dirname + '/__PAGE__'
9+
10+
export default function Page({ params, searchParams }) {
11+
return (
12+
<main>
13+
<p>
14+
This page checks whether runtime/dynamic APIs resolve in the correct
15+
stage (regardless of whether we had a cache miss or not)
16+
</p>
17+
<CachedData cacheKey={CACHE_KEY} label="page" />
18+
<LogAfter label="--- dynamic stage ---" api={() => connection()} />
19+
20+
{/* Runtime */}
21+
<LogAfter label="cookies" api={() => cookies()} />
22+
<LogAfter label="headers" api={() => headers()} />
23+
<LogAfter label="params" api={() => params} />
24+
<LogAfter label="searchParams" api={() => searchParams} />
25+
{/* Dynamic */}
26+
<LogAfter label="connection" api={() => connection()} />
27+
</main>
28+
)
29+
}
30+
31+
function LogAfter({ label, api }: { label: string; api: () => Promise<any> }) {
32+
return (
33+
<Suspense fallback={<div>Waiting for {label}...</div>}>
34+
<LogAfterInner label={label} api={api} />
35+
</Suspense>
36+
)
37+
}
38+
39+
async function LogAfterInner({
40+
label,
41+
api,
42+
}: {
43+
label: string
44+
api: () => Promise<any>
45+
}) {
46+
await api()
47+
console.log(`after ${label}`)
48+
return <div>Finished {label}</div>
49+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Suspense } from 'react'
2+
import { UncachedFetch, CachedData } from '../data-fetching'
3+
import { PrivateCachedData } from './data-fetching'
4+
5+
export const unstable_prefetch = { mode: 'runtime', samples: [{}] }
6+
7+
const CACHE_KEY = '/private-cache/__LAYOUT__'
8+
9+
export default function Layout({ children }: { children: React.ReactNode }) {
10+
return (
11+
<>
12+
{children}
13+
<section>
14+
<h1>Layout</h1>
15+
<p>This data is from a layout</p>
16+
17+
<CachedData label="layout" cacheKey={CACHE_KEY} />
18+
19+
<Suspense fallback="Loading private cache...">
20+
<PrivateCachedData label="layout" cacheKey={CACHE_KEY} />
21+
</Suspense>
22+
23+
<Suspense fallback="Loading uncached fetch...">
24+
<UncachedFetch label="layout" cacheKey={CACHE_KEY} />
25+
</Suspense>
26+
</section>
27+
</>
28+
)
29+
}

0 commit comments

Comments
 (0)