0

I'm trying to render basic example from react-pdf official website (https://react-pdf.org/) but app is freezing while i'm trying to use one of rendering options (i tried PDFViever, usePDF hook, PDFDownloadLink).

When im trying the same example on codesandbox.io everything works fine.

Can someone explain why that could happen and whats possible solutions?

Example code:

import {
  usePDF,
  Page,
  Text,
  View,
  Document,
  StyleSheet,
} from "@react-pdf/renderer";

const styles = StyleSheet.create({
  page: {
    flexDirection: "row",
    backgroundColor: "#E4E4E4"
  },
  section: {
    margin: 10,
    padding: 10,
    flexGrow: 1
  }
});

const MyDocument = () => (
  <Document>
    <Page size="A4" style={styles.page}>
      <View style={styles.section}>
        <Text>Section #1</Text>
      </View>
      <View style={styles.section}>
        <Text>Section #2</Text>
      </View>
    </Page>
  </Document>
);

const ContractorCardView = () => {
  
  // if i comment this line and button in JSX - app not freezes
  const [instance] = usePDF({document: <MyDocument/>})
  
  return <div>
    <button onClick={() => window.open(instance.url)}/>
  </div>
};

Button is rendered, but whole page is not responding, so i can't even click it. When i delete\comment button and usePDF hook then app is loading fine, but obviously i cant render PDF that way))

Same code in codesandbox.io works fine: https://codesandbox.io/s/loving-blackwell-l2dks5?file=/src/App.js

Max Green
  • 241
  • 3
  • 9

1 Answers1

0

I Have the same bug, I believe is something in the package.json, so I'm going to paste the content of the file here. Hope this helps to resolve this bug. If other have the same bug and a common package maybe it is.

{
  "name": "backend-agenda",
  "version": "0.0.1",
  "private": true,
  "main": "lib/index.js",
  "scripts": {
    "build": "gulp bundle",
    "clean": "gulp clean",
    "test": "gulp test"
  },
  "dependencies": {
    "@fluentui/react": "^8.109.2",
    "@microsoft/decorators": "1.15.2",
    "@microsoft/microsoft-graph-client": "^3.0.5",
    "@microsoft/sp-core-library": "1.15.2",
    "@microsoft/sp-dialog": "1.15.2",
    "@microsoft/sp-listview-extensibility": "1.15.2",
    "@microsoft/sp-lodash-subset": "1.15.2",
    "@microsoft/sp-office-ui-fabric-core": "1.15.2",
    "@microsoft/sp-property-pane": "1.15.2",
    "@microsoft/sp-webpart-base": "1.15.2",
    "@pnp/graph": "3.15.0",
    "@pnp/sp": "3.15.0",
    "@pnp/spfx-controls-react": "^3.14.0",
    "@pnp/spfx-property-controls": "3.10.0",
    "@react-pdf/renderer": "2.0.14",
    "@types/jspdf": "^2.0.0",
    "formik": "^2.4.1",
    "jquery": "^3.6.0",
    "jspdf": "^2.5.1",
    "office-ui-fabric-react": "7.185.7",
    "react": "16.13.1",
    "react-beautiful-dnd": "^13.1.1",
    "react-dom": "16.13.1",
    "react-router-dom": "^6.8.1",
    "tslib": "2.3.1",
    "usehooks-ts": "2.9.1",
    "yup": "^1.2.0"
  },
  "devDependencies": {
    "@microsoft/eslint-config-spfx": "1.15.2",
    "@microsoft/eslint-plugin-spfx": "1.15.2",
    "@microsoft/microsoft-graph-types": "^2.26.0",
    "@microsoft/rush-stack-compiler-4.5": "0.2.2",
    "@microsoft/sp-build-web": "1.15.2",
    "@microsoft/sp-module-interfaces": "1.15.2",
    "@rushstack/eslint-config": "2.5.1",
    "@types/react": "16.9.51",
    "@types/react-beautiful-dnd": "^13.1.4",
    "@types/react-dom": "16.9.8",
    "@types/webpack-env": "~1.15.2",
    "@typescript-eslint/eslint-plugin": "^5.59.8",
    "@typescript-eslint/parser": "^5.59.8",
    "ajv": "^6.12.5",
    "eslint": "^8.41.0",
    "eslint-plugin-react-hooks": "4.3.0",
    "gulp": "4.0.2",
    "typescript": "^5.0.4"
  }
}
Fed Liskov
  • 428
  • 4
  • 6