react-pdf
react-pdf copied to clipboard
Getting CSP error
Describe the bug I am trying to consume the package and while rendering I am getting refused to connect due to CSP. Suppose if I add the following lines then it is allowing me to render the pdf.
csp["connect-src"] += " data:";
csp["script-src"] += " 'unsafe-eval'";
csp["frame-src"] += " blob:";
But looks like it is not recommended to add all these CSPs to my codebase.
To Reproduce Steps to reproduce the behavior including code snippet (if applies):
My Code:
import React, { useEffect, useState } from "react";
import { Document, Page, PDFViewer, StyleSheet, View, Text } from "@react-pdf/renderer";
const ReactPdfViewer: React.FC = () => {
const stylesPdf = StyleSheet.create({
page: {
flexDirection: "row",
backgroundColor: "#E4E4E4"
},
section: {
margin: 10,
padding: 10,
flexGrow: 1
}
});
// Create Document Component
const MyDocument = () => (
<Document>
<Page size="A4" style={stylesPdf.page}>
<View style={stylesPdf.section}>
<Text>Section #1</Text>
</View>
<View style={stylesPdf.section}>
<Text>Section #2</Text>
</View>
</Page>
</Document>
);
return (
<>
<PDFViewer>
<MyDocument />
</PDFViewer>
</>
);
};
export default ReactPdfViewer;
Screenshots
Desktop (please complete the following information):
- OS: MacOS
- Browser: chrome, safari
- React-pdf version: @react-pdf/renderer:3.3.4
I'm having the same issue since updating to version 3.3.8, this wasn't the case for version 3.1.14.
I also have the same error on 3.38 :(
I am experiencing this in version 3.1.16. You can observe in the playground that there is a data:application/octet-stream;base64,... request made with each change.
This appears to have some references to Yoga, e.g.
Child already has a owner, it must be removed first.�Cannot set measure function: Nodes with measure functions cannot have children.�Cannot add child: Nodes with measure functions cannot have children.�
The same on my side
This issue is valid for version 3.4.2 as well
Is there any update on the above?
👋 is it going to be fixed in the coming releases?