From 1b59ca9bb5df1f8a9fd8b8a45383fca1a5f06f97 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Thu, 8 Jun 2023 01:10:14 +0000 Subject: [PATCH] feat: non-blocking font importing --- src/core/ui/render.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/ui/render.tsx b/src/core/ui/render.tsx index 10afb44ef..2602a807d 100644 --- a/src/core/ui/render.tsx +++ b/src/core/ui/render.tsx @@ -6,8 +6,12 @@ import satori from 'satori'; const FONT_NAME = 'Roboto'; const FONT_FILES = ['Roboto', 'Roboto-Bold', 'Roboto-Black']; +let robotoFlex: Buffer; +let robotoFlexBold: Buffer; +let robotoFlexBlack: Buffer; + console.log('Importing fonts...'); -const [robotoFlex, robotoFlexBold, robotoFlexBlack] = await Promise.all( +await Promise.all( FONT_FILES.map( (file) => new Promise((resolve, reject) => { @@ -17,8 +21,10 @@ const [robotoFlex, robotoFlexBold, robotoFlexBlack] = await Promise.all( }); }), ), -); -console.log('Fonts imported'); +).then((data) => { + [robotoFlex, robotoFlexBold, robotoFlexBlack] = data; + console.log('Fonts imported'); +}); export default async function render(element: ReactNode) { const svg = await satori(element, {