Skip to content

Commit

Permalink
Fix vercel og package memory leak (#70214)
Browse files Browse the repository at this point in the history
# Conflicts:
#	pnpm-lock.yaml
  • Loading branch information
huozhi authored and ijjk committed Sep 19, 2024
1 parent 62fbd7f commit 49566f5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"@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 @@ -210,10 +210,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
8 changes: 4 additions & 4 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 49566f5

Please sign in to comment.