Skip to content

Commit 3e7a510

Browse files
leerobhuozhi
andauthored
docs: opengraph-image files work with the node.js runtime (#75274)
Co-authored-by: Jiachi Liu <[email protected]>
1 parent e3e337b commit 3e7a510

File tree

9 files changed

+15
-81
lines changed

9 files changed

+15
-81
lines changed

docs/01-app/03-building-your-application/01-routing/06-loading-ui-and-streaming.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ In the same folder, `loading.js` will be nested inside `layout.js`. It will auto
6161
6262
## Streaming with Suspense
6363

64-
In addition to `loading.js`, you can also manually create Suspense Boundaries for your own UI components. The App Router supports streaming with [Suspense](https://react.dev/reference/react/Suspense) for both [Node.js and Edge runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes).
64+
In addition to `loading.js`, you can also manually create Suspense Boundaries for your own UI components. The App Router supports streaming with [Suspense](https://react.dev/reference/react/Suspense).
6565

6666
> **Good to know**:
6767
>

docs/01-app/03-building-your-application/06-optimizing/04-metadata.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ export async function GET() {
286286
>
287287
> - Examples are available in the [Vercel OG Playground](https://og-playground.vercel.app/).
288288
> - `ImageResponse` uses [@vercel/og](https://vercel.com/docs/concepts/functions/edge-functions/og-image-generation), [Satori](https://github.com/vercel/satori), and Resvg to convert HTML and CSS into PNG.
289-
> - Only the Edge Runtime is supported. The default Node.js runtime will not work.
290289
> - Only flexbox and a subset of CSS properties are supported. Advanced layouts (e.g. `display: grid`) will not work.
291290
> - Maximum bundle size of `500KB`. The bundle size includes your JSX, CSS, fonts, images, and any other assets. If you exceed the limit, consider reducing the size of any assets or fetching at runtime.
292291
> - Only `ttf`, `otf`, and `woff` font formats are supported. To maximize the font parsing speed, `ttf` or `otf` are preferred over `woff`.

docs/01-app/04-api-reference/03-file-conventions/01-metadata/opengraph-image.mdx

Lines changed: 14 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ The easiest way to generate an image is to use the [ImageResponse](/docs/app/api
9696

9797
```tsx filename="app/about/opengraph-image.tsx" switcher
9898
import { ImageResponse } from 'next/og'
99-
100-
export const runtime = 'edge'
99+
import { readFile } from 'node:fs/promises'
100+
import { join } from 'node:path'
101101

102102
// Image metadata
103103
export const alt = 'About Acme'
@@ -110,10 +110,10 @@ export const contentType = 'image/png'
110110

111111
// Image generation
112112
export default async function Image() {
113-
// Font
114-
const interSemiBold = fetch(
115-
new URL('./Inter-SemiBold.ttf', import.meta.url)
116-
).then((res) => res.arrayBuffer())
113+
// Font loading, process.cwd() is Next.js project directory
114+
const interSemiBold = await readFile(
115+
join(process.cwd(), 'assets/Inter-SemiBold.ttf')
116+
)
117117

118118
return new ImageResponse(
119119
(
@@ -140,7 +140,7 @@ export default async function Image() {
140140
fonts: [
141141
{
142142
name: 'Inter',
143-
data: await interSemiBold,
143+
data: interSemiBold,
144144
style: 'normal',
145145
weight: 400,
146146
},
@@ -152,8 +152,8 @@ export default async function Image() {
152152

153153
```jsx filename="app/about/opengraph-image.js" switcher
154154
import { ImageResponse } from 'next/og'
155-
156-
export const runtime = 'edge'
155+
import { readFile } from 'node:fs/promises'
156+
import { join } from 'node:path'
157157

158158
// Image metadata
159159
export const alt = 'About Acme'
@@ -166,10 +166,10 @@ export const contentType = 'image/png'
166166

167167
// Image generation
168168
export default async function Image() {
169-
// Font
170-
const interSemiBold = fetch(
171-
new URL('./Inter-SemiBold.ttf', import.meta.url)
172-
).then((res) => res.arrayBuffer())
169+
// Font loading, process.cwd() is Next.js project directory
170+
const interSemiBold = await readFile(
171+
join(process.cwd(), 'assets/Inter-SemiBold.ttf')
172+
)
173173

174174
return new ImageResponse(
175175
(
@@ -196,7 +196,7 @@ export default async function Image() {
196196
fonts: [
197197
{
198198
name: 'Inter',
199-
data: await interSemiBold,
199+
data: interSemiBold,
200200
style: 'normal',
201201
weight: 400,
202202
},
@@ -400,62 +400,6 @@ export default async function Image({ params }) {
400400
}
401401
```
402402

403-
#### Using Edge runtime with local assets
404-
405-
This example uses the Edge runtime to fetch a local image on the file system and passes it as an `ArrayBuffer` to the `src` attribute of an `<img>` element. The local asset should be placed relative to the example source file location.
406-
407-
```tsx filename="app/opengraph-image.tsx" switcher
408-
import { ImageResponse } from 'next/og'
409-
410-
export const runtime = 'edge'
411-
412-
export default async function Image() {
413-
const logoSrc = await fetch(new URL('./logo.png', import.meta.url)).then(
414-
(res) => res.arrayBuffer()
415-
)
416-
417-
return new ImageResponse(
418-
(
419-
<div
420-
style={{
421-
display: 'flex',
422-
alignItems: 'center',
423-
justifyContent: 'center',
424-
}}
425-
>
426-
<img src={logoSrc} height="100" />
427-
</div>
428-
)
429-
)
430-
}
431-
```
432-
433-
```jsx filename="app/opengraph-image.js" switcher
434-
import { ImageResponse } from 'next/og'
435-
436-
export const runtime = 'edge'
437-
438-
export default async function Image() {
439-
const logoSrc = await fetch(new URL('./logo.png', import.meta.url)).then(
440-
(res) => res.arrayBuffer()
441-
)
442-
443-
return new ImageResponse(
444-
(
445-
<div
446-
style={{
447-
display: 'flex',
448-
alignItems: 'center',
449-
justifyContent: 'center',
450-
}}
451-
>
452-
<img src={logoSrc} height="100" />
453-
</div>
454-
)
455-
)
456-
}
457-
```
458-
459403
#### Using Node.js runtime with local assets
460404

461405
This example uses the Node.js runtime to fetch a local image on the file system and passes it as an `ArrayBuffer` to the `src` attribute of an `<img>` element. The local asset should be placed relative to the root of your project, rather than the location of the example source file.

docs/01-app/04-api-reference/04-functions/revalidatePath.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ description: API Reference for the revalidatePath function.
77

88
> **Good to know**:
99
>
10-
> - `revalidatePath` is available in both [Node.js and Edge runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes).
1110
> - `revalidatePath` only invalidates the cache when the included path is next visited. This means calling `revalidatePath` with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited.
1211
> - Currently, `revalidatePath` invalidates all the routes in the [client-side Router Cache](/docs/app/building-your-application/caching#client-side-router-cache) when used in a server action. This behavior is temporary and will be updated in the future to apply only to the specific path.
1312
> - Using `revalidatePath` invalidates **only the specific path** in the [server-side Route Cache](/docs/app/building-your-application/caching#full-route-cache).

docs/01-app/04-api-reference/04-functions/revalidateTag.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ description: API Reference for the revalidateTag function.
77

88
> **Good to know**:
99
>
10-
> - `revalidateTag` is available in both [Node.js and Edge runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes).
1110
> - `revalidateTag` only invalidates the cache when the path is next visited. This means calling `revalidateTag` with a dynamic route segment will not immediately trigger many revalidations at once. The invalidation only happens when the path is next visited.
1211
1312
## Parameters

docs/01-app/04-api-reference/04-functions/unstable_expirePath.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ version: unstable
88

99
> **Good to know**:
1010
>
11-
> - `unstable_expirePath` is available in both [Node.js and Edge runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes).
1211
> - `unstable_expirePath` only invalidates the cache when the included path is next visited. This means calling `unstable_expirePath` with a dynamic route segment will not immediately trigger many expirations at once. The invalidation only happens when the path is next visited.
1312
> - Currently, `unstable_expirePath` invalidates all the routes in the [client-side Router Cache](/docs/app/building-your-application/caching#client-side-router-cache) when used in a server action. This behavior is temporary and will be updated in the future to apply only to the specific path.
1413
> - Using `unstable_expirePath` invalidates **only the specific path** in the [server-side Route Cache](/docs/app/building-your-application/caching#full-route-cache).

docs/01-app/04-api-reference/04-functions/unstable_expireTag.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ version: unstable
88

99
> **Good to know**:
1010
>
11-
> - `unstable_expireTag` is available in both [Node.js and Edge runtimes](/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes).
1211
> - `unstable_expireTag` only invalidates the cache when the path is next visited. This means calling `unstable_expireTag` with a dynamic route segment will not immediately trigger many expirations at once. The invalidation only happens when the path is next visited.
1312
1413
## Reference
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export { GET, POST } from "@/auth";
2-
export const runtime = "edge";

examples/with-mux-video/app/v/[playbackId]/page.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ const Code = ({ children }: { children: React.ReactNode }) => (
4444
</code>
4545
);
4646

47-
// this function communicates with no external services and relies on no Node APIs
48-
// it's perfect for the edge
49-
export const runtime = "edge";
50-
5147
export default async function Page(props: { params: Promise<Params> }) {
5248
const params = await props.params;
5349

0 commit comments

Comments
 (0)