Skip to content

Commit

Permalink
Fix vercel og package memory leak (#70214)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Sep 18, 2024
1 parent 5791706 commit 2b73531
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"@typescript-eslint/parser": "7.16.0",
"@vercel/devlow-bench": "workspace:*",
"@vercel/fetch": "6.1.1",
"@vercel/og": "0.6.2",
"@vercel/og": "0.6.3",
"abort-controller": "3.0.0",
"alex": "9.1.0",
"amphtml-validator": "1.0.35",
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/compiled/@vercel/og/index.edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -18784,7 +18784,11 @@ async function render(satori, resvg, opts, defaultFonts, element) {
value: options.width
}
});
return resvgJS.render().asPng();
const pngData = resvgJS.render();
const pngBuffer = pngData.asPng();
pngData.free();
resvgJS.free();
return pngBuffer;
}

// src/figma/index.tsx
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/compiled/@vercel/og/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18786,7 +18786,11 @@ async function render(satori2, resvg, opts, defaultFonts, element) {
value: options.width
}
});
return resvgJS.render().asPng();
const pngData = resvgJS.render();
const pngBuffer = pngData.asPng();
pngData.free();
resvgJS.free();
return pngBuffer;
}

// src/figma/index.tsx
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/compiled/@vercel/og/og.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function render(satori: any, resvg: any, opts: any, defaultFonts: any, element: any): Promise<any>;
export default function render(satori: any, resvg: any, opts: any, defaultFonts: any, element: any): Promise<Uint8Array>;
2 changes: 1 addition & 1 deletion packages/next/src/compiled/@vercel/og/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vercel/og",
"version": "0.6.2",
"version": "0.6.3",
"LICENSE": "MLP-2.0",
"type": "module",
"main": "./index.node.js",
Expand Down
7 changes: 3 additions & 4 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ export async function copy_vercel_og(task, opts) {
.run({ every: true }, function* (file) {
const source = file.data.toString()
// Refers to copied satori types
file.data = source.replace(
/['"]satori['"]/g,
'"next/dist/compiled/@vercel/og/satori"'
)
file.data = source
.replace(/['"]satori['"]/g, '"next/dist/compiled/@vercel/og/satori"')
.replace("typeof import('@resvg/resvg-wasm')", 'any')
})
.target('src/compiled/@vercel/og')

Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b73531

Please sign in to comment.