Skip to content

🎥 Make videos programmatically with React

`@remotion/google-fonts`: Try to load font 3 times

Jonny Burger4e97efe728ed
diff --git a/packages/google-fonts/src/base.ts b/packages/google-fonts/src/base.ts
index 866903bab5..7a6321215d 100644
--- a/packages/google-fonts/src/base.ts
+++ b/packages/google-fonts/src/base.ts
@@ -93,23 +93,34 @@ export const loadFonts = (
},
);
- // Load font-face
- const promise = fontFace
- .load()
- .then(() => {
- (options?.document ?? document).fonts.add(fontFace);
- continueRender(handle);
- })
- .catch((err) => {
- // Mark font as not loaded
- loadedFonts[fontKey] = undefined;
- throw err;
- });
+ let attempts = 2;
- // Mark font as loaded
- loadedFonts[fontKey] = promise;
+ const tryToLoad = () => {
+ // Load font-face
+ const promise = fontFace
+ .load()
+ .then(() => {
+ (options?.document ?? document).fonts.add(fontFace);
+ continueRender(handle);
+ })
+ .catch((err) => {
+ // Mark font as not loaded
+ loadedFonts[fontKey] = undefined;
+ if (attempts === 0) {
+ throw err;
+ } else {
+ attempts--;
+ tryToLoad();
+ }
+ });
- promises.push(promise);
+ // Mark font as loaded
+ loadedFonts[fontKey] = promise;
+
+ promises.push(promise);
+ };
+
+ tryToLoad();
}
}
}