Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix font not rendered on init in FF (#1197)

David Luzar036978b83798
diff --git a/src/components/App.tsx b/src/components/App.tsx
index 53d63216e8..a9ecbfa01b 100644
--- a/src/components/App.tsx
+++ b/src/components/App.tsx
@@ -331,6 +331,23 @@ export class App extends React.Component<any, AppState> {
}
}
+ // rerender text elements on font load to fix #637
+ try {
+ await Promise.race([
+ document.fonts?.ready?.then(() => {
+ globalSceneState.getAllElements().forEach((element) => {
+ if (isTextElement(element)) {
+ invalidateShapeForElement(element);
+ }
+ });
+ }),
+ // if fonts don't load in 1s for whatever reason, don't block the UI
+ new Promise((resolve) => setTimeout(resolve, 1000)),
+ ]);
+ } catch (error) {
+ console.error(error);
+ }
+
if (this.state.isLoading) {
this.setState({ isLoading: false });
}
diff --git a/src/global.d.ts b/src/global.d.ts
index b86bd183a6..9c54b70bd0 100644
--- a/src/global.d.ts
+++ b/src/global.d.ts
@@ -1,3 +1,9 @@
+interface Document {
+ fonts?: {
+ ready?: Promise<void>;
+ };
+}
+
interface Window {
ClipboardItem: any;
}