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
827 B
TypeScript
39 lines
827 B
TypeScript
import { ImageResponse } from 'next/og'
|
|
|
|
export const alt = 'About Acme'
|
|
export const size = { width: 1200, height: 630 }
|
|
export const contentType = 'image/png'
|
|
|
|
async function fetchPostData() {
|
|
'use cache'
|
|
|
|
return { title: 'Test', created: Date.now() }
|
|
}
|
|
|
|
export default async function Image() {
|
|
const post = await fetchPostData()
|
|
|
|
return new ImageResponse(
|
|
(
|
|
<div
|
|
style={{
|
|
fontSize: 48,
|
|
background: 'white',
|
|
width: '100%',
|
|
height: '100%',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
flexDirection: 'column',
|
|
}}
|
|
>
|
|
<h1>{post.title}</h1>
|
|
<p style={{ fontSize: 32 }}>
|
|
{new Date(post.created).toLocaleTimeString()}
|
|
</p>
|
|
</div>
|
|
),
|
|
size
|
|
)
|
|
}
|