mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
[flakiness metric](https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40git.repository.id%3A%22github.com%2Fvercel%2Fnext.js%22%20%40test.name%3A%22use-cache-custom-handler%20should%20use%20a%20modern%20custom%20cache%20handler%20if%20provided%22%20%40test.type%3A%22nextjs%22%20%40test.status%3A%22fail%22%20%40git.branch%3Acanary&agg_m=count&agg_m_source=base&agg_t=count&fromUser=true&index=citest&start=1759310750664&end=1761902750664&paused=false) The test page used a low revalidate time of 3 seconds. In CI, sometimes that much time passes between the first and second request, causing the test to fail when comparing the data values (locally reproducible with `{ cpuThrottleRate: 20 }`). Increasing the revalidate time to 6 seconds should make the test more robust.
66 lines
1.3 KiB
TypeScript
66 lines
1.3 KiB
TypeScript
import { Suspense } from 'react'
|
|
import { cacheLife, cacheTag, revalidatePath, updateTag } from 'next/cache'
|
|
import { redirect } from 'next/navigation'
|
|
import { connection } from 'next/server'
|
|
import React from 'react'
|
|
|
|
async function getData() {
|
|
'use cache'
|
|
|
|
cacheLife({ revalidate: 6 })
|
|
cacheTag('modern')
|
|
|
|
return new Date().toISOString()
|
|
}
|
|
|
|
async function AsyncComp() {
|
|
let data = await getData()
|
|
|
|
return <p id="data">{data}</p>
|
|
}
|
|
|
|
export default async function Home() {
|
|
await connection()
|
|
|
|
return (
|
|
<main>
|
|
<Suspense fallback={<p>Loading...</p>}>
|
|
<AsyncComp />
|
|
</Suspense>
|
|
<form>
|
|
<button
|
|
id="revalidate-tag"
|
|
formAction={async () => {
|
|
'use server'
|
|
|
|
updateTag('modern')
|
|
}}
|
|
>
|
|
Revalidate Tag
|
|
</button>{' '}
|
|
<button
|
|
id="revalidate-path"
|
|
formAction={async () => {
|
|
'use server'
|
|
|
|
revalidatePath('/')
|
|
}}
|
|
>
|
|
Revalidate Path
|
|
</button>{' '}
|
|
<button
|
|
id="revalidate-redirect"
|
|
formAction={async () => {
|
|
'use server'
|
|
|
|
updateTag('modern')
|
|
redirect('/')
|
|
}}
|
|
>
|
|
Revalidate Tag & Redirect
|
|
</button>
|
|
</form>
|
|
</main>
|
|
)
|
|
}
|