diff --git a/src/components/App.tsx b/src/components/App.tsx index 53d63216..a9ecbfa0 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -331,6 +331,23 @@ export class App extends React.Component { } } + // 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 b86bd183..9c54b70b 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,3 +1,9 @@ +interface Document { + fonts?: { + ready?: Promise; + }; +} + interface Window { ClipboardItem: any; }