diegomura / diegomura/react-pdf
Multiple usage of `usePdf` doesn't render fonts properly
- Dominant language
- TypeScript
- Stars
- 16.8k
- Forks
- 1.3k
- Avg merge
- 5h 6m
- Merged PRs (30d)
- 52
Description
**Describe the bug**
Registered fonts are applied only for the first document when using `usePdf` multiple times in a single component.
**To Reproduce**
Steps to reproduce the behavior including code snippet (if applies):
1. Create 2 documents
2. Register the same fonts for each of them
```
import robotoMedium from './fonts/Roboto-Medium.ttf'
import robotoRegular from './fonts/Roboto-Regular.ttf'
Font.register({
family: 'Roboto',
fonts: [
{
src: robotoRegular,
fontWeight: 'normal'
},
{
src: robotoMedium,
fontWeight: 'medium'
}
]
})
```
3. Apply fonts in styles for both documents
4. Create a component
5. Import both documents
6. use `usePdf` twice in the created component:
```
const [instanceOne] = usePdf({ document: })
const [instanceTwo] = usePdf({ document: })
```
7. Add anchor tag and download both PDFs
**Actual behavior**
Downloading both `instanceOne` and `instanceTwo` results in displaying proper fonts only for `instanceOne`.
If I'd change the order and it will be:
```
const [instanceTwo] = usePdf({ document: })
const [instanceOne] = usePdf({ document: })
```
Then the `instanceTwo` is rendered properly and `instanceOne` is not.
**Expected behavior**
Fonts should be rendered properly for both documents
**Desktop (please complete the following information):**
- OS: Ubuntu
- Browser: Chrome
- React-pdf version v2.1.1
Contributor guide
Assessment
This issue has not been assessed yet.