mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Adds support for using `"use cache"` in the special metadata route handlers like [`sitemap.ts`](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generating-a-sitemap-using-code-js-ts), [`opengraph-image.tsx`](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/opengraph-image#generate-images-using-code-js-ts-tsx), [`icon.tsx`](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/app-icons#generate-icons-using-code-js-ts-tsx), and other [metadata files](https://nextjs.org/docs/app/api-reference/file-conventions/metadata). reverts #71225 fixes #74146 closes NAR-51 As a follow-up we need to ensure that opengraph image responses do not bail out of static generation when `dynamicIO` is enabled.
39 lines
729 B
TypeScript
39 lines
729 B
TypeScript
import { ImageResponse } from 'next/og'
|
|
import { setTimeout } from 'timers/promises'
|
|
|
|
export const size = { width: 32, height: 32 }
|
|
export const contentType = 'image/png'
|
|
|
|
async function fetchIconLetter() {
|
|
'use cache'
|
|
|
|
// Simulate I/O
|
|
await setTimeout(100)
|
|
|
|
return 'N'
|
|
}
|
|
|
|
export default async function Icon() {
|
|
const letter = await fetchIconLetter()
|
|
|
|
return new ImageResponse(
|
|
(
|
|
<div
|
|
style={{
|
|
fontSize: 24,
|
|
background: 'black',
|
|
width: '100%',
|
|
height: '100%',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
color: 'white',
|
|
}}
|
|
>
|
|
{letter}
|
|
</div>
|
|
),
|
|
{ ...size }
|
|
)
|
|
}
|