Skip to content

Commit

Permalink
fix: empty fonts array crashing frame render (#472)
Browse files Browse the repository at this point in the history
* fix: empty `fonts` array crashing frame render

* chore: changesets
  • Loading branch information
dalechyn authored Aug 13, 2024
1 parent 88f1b89 commit 8529049
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-pans-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"frog": patch
---

Fixed an issue where a frame without any fonts passed would crash the render process.
25 changes: 17 additions & 8 deletions src/frog-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,14 @@ export class FrogBase<
const defaultImageOptionsFonts = defaultImageOptions?.fonts ?? []
const imageOptionsFonts =
(imageOptions as ImageOptions | undefined)?.fonts ?? []
return [
const fonts = [
...uiFonts,
...optionsFonts,
...defaultImageOptionsFonts,
...imageOptionsFonts,
]
if (fonts.length === 0) return undefined
return fonts
})()

return new ImageResponse(image_, {
Expand Down Expand Up @@ -859,19 +861,23 @@ export class FrogBase<
const defaultImageOptionsFonts = defaultImageOptions?.fonts ?? []
const imageOptionsFonts =
(imageOptions as ImageOptions | undefined)?.fonts ?? []
return [
const fonts = [
...uiFonts,
...optionsFonts,
...defaultImageOptionsFonts,
...imageOptionsFonts,
]

if (fonts.length === 0) return undefined
return fonts
})()
const groupedFonts = new Map<string, NonNullable<typeof fonts>>()
for (const font of fonts) {
const key = `${font.source ? `${font.source}:` : ''}${font.name}`
if (groupedFonts.has(key)) groupedFonts.get(key)?.push(font)
else groupedFonts.set(key, [font])
}
if (fonts)
for (const font of fonts) {
const key = `${font.source ? `${font.source}:` : ''}${font.name}`
if (groupedFonts.has(key)) groupedFonts.get(key)?.push(font)
else groupedFonts.set(key, [font])
}
const googleFonts = []
for (const item of groupedFonts) {
const [, fonts] = item
Expand Down Expand Up @@ -1067,12 +1073,15 @@ export class FrogBase<
const defaultImageOptionsFonts = defaultImageOptions?.fonts ?? []
const imageOptionsFonts = response.data.imageOptions?.fonts ?? []

return [
const fonts = [
...uiFonts,
...optionsFonts,
...defaultImageOptionsFonts,
...imageOptionsFonts,
]

if (fonts.length === 0) return undefined
return fonts
})()

const {
Expand Down

0 comments on commit 8529049

Please sign in to comment.