mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
This is relevant if the cache is in a broken state or the keys or entries are not suitable (e.g. an entry that's to large to be stored). Revealed several oddities: 1. cache handler have no no sources content (not too bad since that means the codeframe points into the problem `use cache` function which is usually the cause) 2. A throwing `set` is swallowed in dev 3. A throwing `get` is logged as a caught error and an unhandled rejection. This is spammy.
33 lines
742 B
TypeScript
33 lines
742 B
TypeScript
import { Suspense } from 'react'
|
|
|
|
async function getCachedData(input: string) {
|
|
'use cache'
|
|
|
|
return `cached data for input: ${input}`
|
|
}
|
|
|
|
async function CachedData({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ input?: string }>
|
|
}) {
|
|
// Reading `searchParams` and passing the value into the cached function
|
|
// ensures that the cache handler is only invoked at request time, and not
|
|
// during build-time prerendering.
|
|
const { input = 'default' } = await searchParams
|
|
|
|
return <p>{await getCachedData(input)}</p>
|
|
}
|
|
|
|
export default function Page({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ input?: string }>
|
|
}) {
|
|
return (
|
|
<Suspense fallback={null}>
|
|
<CachedData searchParams={searchParams} />
|
|
</Suspense>
|
|
)
|
|
}
|