diegomura / diegomura/react-pdf

BlobProvider in loop

Open
#1,315 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
16.8k
Forks
1.3k
Avg merge
5h 6m
Merged PRs (30d)
52

Description

After updating to v2.0 appeared an unexpected behavior in BlobProvider: during rendering on the fly, the props "loading" and "url" changes continuously, making the document re-render multiple times, as you can see in the following screenshot:

![image](https://user-images.githubusercontent.com/56065091/117954741-9d52c880-b317-11eb-8294-0621c80b9141.png)

BlobProvider is located in the parent component "ReportGenerator.js", the document is located in the child component "MyDocument". Here an extract of my code:

```

}
>
{({ blob, url, loading, error }) => {
console.log(blob, url, "loading:", loading, "error:", error);
if (error) {
return {error};
}
else if (!blob) {
return (



Loading...

);
} else {
return (


}
document={

}
fileName={`${props.kitData._id}.pdf`}
>

{" "}








);
}
}}

```

In MyDocument component there is no state change, just StyleSheet.create method and React Pdf components taking data from props. Props and states in parent component don't change as well.

After this multiple re-rendering, the pdf at last appears. Moreover, if I use Dynamic content, like the page number in a footer, the re-rendering go in infinite loop, crashing the browser tab.

Have you and idea why this is happening? Thank you so much in advance!

Desktop:
- OS: [Windows]
- Browser [chrome]
- React-pdf version [2.0.12]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.