Custom fonts cause the page to break and leak resources
See original GitHub issueOS: macOS Mojave 10.14.3 Beta
React-pdf version: v1.1.0
Description:
Applying a custom font in the browser seems to cause some sort of resources leak, ultimately preventing the document from rendering.
How to replicate issue including code snippet (if applies):
I put together a reproduction repo: https://github.com/puregarlic/react-pdf-repro
This is all the code needed to break it:
import React from 'react'
import { PDFViewer, Document, Font, Page, Text } from '@react-pdf/renderer'
// font included in the example repository
import PTSansCaption from './fonts/PT_Sans-Caption-Web-Regular.ttf'
Font.register(PTSansCaption, { family: 'PT Sans Caption' })
const App = () => (
<PDFViewer width="100%" height="100%">
<Document>
<Page>
{/* Removing the style prop fixes the page */}
<Text style={{ fontFamily: 'PT Sans Caption' }}>Hello, world</Text>
</Page>
</Document>
</PDFViewer>
)
export default App
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Memory leaks with custom font for set custom font
The following code for setting custom fonts slows down my whole app. how do i modify it to avoid memory leaks and increase...
Read more >How to load web fonts to avoid performance issues and speed ...
Custom web fonts are used everywhere around the world, but many (oh so many) sites load them improperly. This causes a lot of...
Read more >CSS Fonts Module Level 4 - W3C
Define custom display and timeout policies per element. ... An optional font must never cause the layout of the page to "jump" as...
Read more >How to avoid layout shifts caused by web fonts - Simon Hearne
One of the biggest causes of layout shifts for my clients is late-loading web fonts, let's look at how to optimise them!
Read more >Avoid memory and resource leaks - DevExpress Support
Among many reasons that cause memory leaks, the most common is not calling the Dispose method to destroy objects that are no longer...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@baileysingleton I added example for concrete case when
create-react-app
is used to build assets with webpack and insert script to the page:In such case you need to add host prefix so browser can determine how to download this font.
But if you import font inside
Node
application (without webpack loader) you can use relative path.@maxsbelt How come relative paths no longer work? Makes it a bit tough for production use, as urls work for development, but relative paths with Node would be the preferred use scenario.
Thanks!