Skip to content

Commit 8397add

Browse files
committed
test environment labels with sync IO
1 parent b3c47a4 commit 8397add

File tree

8 files changed

+156
-3
lines changed

8 files changed

+156
-3
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,51 @@ describe.each([
308308
await testNavigation(path, assertLogs)
309309
}
310310
})
311+
312+
it('sync IO in the static phase', async () => {
313+
const path = '/sync-io/static'
314+
315+
const assertLogs = async (browser: Playwright) => {
316+
const logs = await browser.log()
317+
318+
assertLog(logs, 'after first cache', 'Prerender')
319+
// sync IO in the static stage errors and advances to Server.
320+
assertLog(logs, 'after sync io', 'Server')
321+
assertLog(logs, 'after cache read - page', 'Server')
322+
}
323+
324+
if (isInitialLoad) {
325+
await testInitialLoad(path, assertLogs)
326+
} else {
327+
await testNavigation(path, assertLogs)
328+
}
329+
})
330+
331+
it('sync IO in the runtime phase', async () => {
332+
const path = '/sync-io/runtime'
333+
334+
const assertLogs = async (browser: Playwright) => {
335+
const logs = await browser.log()
336+
337+
assertLog(logs, 'after first cache', 'Prerender')
338+
assertLog(logs, 'after cookies', RUNTIME_ENV)
339+
if (hasRuntimePrefetch) {
340+
// if runtime prefetching is on, sync IO in the runtime stage errors and advances to Server.
341+
assertLog(logs, 'after sync io', 'Server')
342+
assertLog(logs, 'after cache read - page', 'Server')
343+
} else {
344+
// if runtime prefetching is not on, sync IO in the runtime stage does nothing.
345+
assertLog(logs, 'after sync io', RUNTIME_ENV)
346+
assertLog(logs, 'after cache read - page', RUNTIME_ENV)
347+
}
348+
}
349+
350+
if (isInitialLoad) {
351+
await testInitialLoad(path, assertLogs)
352+
} else {
353+
await testNavigation(path, assertLogs)
354+
}
355+
})
311356
})
312357
}
313358
)

test/development/app-dir/cache-components-dev-warmup/fixtures/with-prefetch-config/app/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export default function Page() {
2020
<li>
2121
<Link href="/apis/123">/apis/123</Link>
2222
</li>
23+
<li>
24+
<Link href="/sync-io/static">/sync-io/static</Link>
25+
</li>
26+
<li>
27+
<Link href="/sync-io/runtime">/sync-io/runtime</Link>
28+
</li>
2329
</ul>
2430
</main>
2531
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Suspense } from 'react'
2+
import { CachedData, getCachedData } from '../../data-fetching'
3+
import { cookies } from 'next/headers'
4+
5+
export const unstable_prefetch = { mode: 'runtime', samples: [{}] }
6+
7+
const CACHE_KEY = __dirname + '/__PAGE__'
8+
9+
export default async function Page() {
10+
return (
11+
<main>
12+
<h1>Sync IO - runtime stage</h1>
13+
<Suspense fallback={<div>Loading...</div>}>
14+
<Runtime />
15+
</Suspense>
16+
</main>
17+
)
18+
}
19+
20+
async function Runtime() {
21+
await getCachedData(CACHE_KEY + '-1')
22+
console.log(`after first cache`)
23+
24+
await cookies()
25+
console.log(`after cookies`)
26+
27+
Date.now()
28+
console.log(`after sync io`)
29+
30+
return <CachedData label="page" cacheKey={CACHE_KEY} />
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { CachedData, getCachedData } from '../../data-fetching'
2+
3+
export const unstable_prefetch = { mode: 'runtime', samples: [{}] }
4+
5+
const CACHE_KEY = __dirname + '/__PAGE__'
6+
7+
export default async function Page() {
8+
await getCachedData(CACHE_KEY + '-1')
9+
console.log(`after first cache`)
10+
11+
Date.now()
12+
console.log(`after sync io`)
13+
14+
return (
15+
<main>
16+
<h1>Sync IO - static stage</h1>
17+
<CachedData label="page" cacheKey={CACHE_KEY} />
18+
</main>
19+
)
20+
}

test/development/app-dir/cache-components-dev-warmup/fixtures/without-prefetch-config/app/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export default function Page() {
2020
<li>
2121
<Link href="/apis/123">/apis/123</Link>
2222
</li>
23+
<li>
24+
<Link href="/sync-io/static">/sync-io/static</Link>
25+
</li>
26+
<li>
27+
<Link href="/sync-io/runtime">/sync-io/runtime</Link>
28+
</li>
2329
</ul>
2430
</main>
2531
)
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 { CachedData, getCachedData } from '../../data-fetching'
3+
import { cookies } from 'next/headers'
4+
5+
const CACHE_KEY = __dirname + '/__PAGE__'
6+
7+
export default async function Page() {
8+
return (
9+
<main>
10+
<h1>Sync IO - runtime stage</h1>
11+
<Suspense fallback={<div>Loading...</div>}>
12+
<Runtime />
13+
</Suspense>
14+
</main>
15+
)
16+
}
17+
18+
async function Runtime() {
19+
await getCachedData(CACHE_KEY + '-1')
20+
console.log(`after first cache`)
21+
22+
await cookies()
23+
console.log(`after cookies`)
24+
25+
Date.now()
26+
console.log(`after sync io`)
27+
28+
return <CachedData label="page" cacheKey={CACHE_KEY} />
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { CachedData, getCachedData } from '../../data-fetching'
2+
3+
const CACHE_KEY = __dirname + '/__PAGE__'
4+
5+
export default async function Page() {
6+
await getCachedData(CACHE_KEY + '-1')
7+
console.log(`after first cache`)
8+
9+
Date.now()
10+
console.log(`after sync io`)
11+
12+
return (
13+
<main>
14+
<h1>Sync IO - static stage</h1>
15+
<CachedData label="page" cacheKey={CACHE_KEY} />
16+
</main>
17+
)
18+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type { NextConfig } from 'next'
22

33
const nextConfig: NextConfig = {
4-
experimental: {
5-
cacheComponents: true,
6-
},
4+
cacheComponents: true,
75
}
86

97
export default nextConfig

0 commit comments

Comments
 (0)