question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom fonts cause the page to break and leak resources

See original GitHub issue

OS: 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
maxsbeltcommented, Jan 9, 2019

@baileysingleton I added example for concrete case when create-react-app is used to build assets with webpack and insert script to the page:

import Arial from './fonts/Arial.ttf'
// Arial variable be something like `/fonts/Arial.23nlk23l.ttf`

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.

0reactions
baileysingletoncommented, Jan 8, 2019

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found