diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.34k stars 1.13k forks source link

On the fly rendering - Cannot set property 'getCurrentStack' of undefined #565

Closed Lilian1331 closed 3 years ago

Lilian1331 commented 5 years ago

There is a issue when I apply "On the fly rendering" in my react webpage. https://react-pdf.org/advanced#on-the-fly-rendering

import { PDFDownloadLink, Document, Page } from '@react-pdf/renderer'

const MyDoc = () => (
   <Document>
      <Page>ABC</Page>
    </Document>
)

then inside the react export class:

public render(): React.ReactElement<IJsomProps> {
     <div>Export</div>
     <div>
       <PDFDownloadLink document={<MyDoc />} fileName="somename.pdf">
         {({ blob, url, loading, error }) => (loading ? 'Loading document...' : 'Download now!')} 
       </PDFDownloadLink> 
     </div>
}

it gives me this error image

Any help thanks.

diegomura commented 5 years ago

What version of React are you using?

Lilian1331 commented 5 years ago

What version of React are you using?

I am using "react": "16.7.0",

diegomura commented 5 years ago

Oh. Wait. Not sure if that's what causing this, but you cannot render a text directly inside a <Page>. You must always use <Text>:

import { PDFDownloadLink, Document, Page, Text } from '@react-pdf/renderer'

const MyDoc = () => (
   <Document>
      <Page>
        <Text>ABC</Text>
       </Page>
    </Document>
)

Let me know if that solves your issue

Lilian1331 commented 5 years ago

Oh. Wait. Not sure if that's what causing this, but you cannot render a text directly inside a <Page>. You must always use <Text>:

import { PDFDownloadLink, Document, Page, Text } from '@react-pdf/renderer'

const MyDoc = () => (
   <Document>
      <Page>
        <Text>ABC</Text>
       </Page>
    </Document>
)

Let me know if that solves your issue

Thanks, but the issue cannot be solved. Am I missing some configurations? Or I can't directly put the <PDFDownloadLink> inside the render function?

diegomura commented 5 years ago

I have some doubts about your code that makes me thing that maybe this is not even a react-pdf issue. All errors are from react-reconciler, which is used by react-pdf but also by react itself

I just tried on my end and everything is working fine. Please try this:

const MyDoc = () => (
  <Document>
    <Page>
      <Text>ABC</Text>
    </Page>
  </Document>
)

class App extends React.Component {
  render() {
    return (
      <div> // or Fragment if you want
        <div>Export</div>
        <div>
          <PDFDownloadLink document={<MyDoc />} fileName="somename.pdf">
            {({ loading }) => loading ? 'Loading' : 'Download'}
          </PDFDownloadLink>
        </div>
      </div>
    )
  }
}
Lilian1331 commented 5 years ago

Yes I have the exact same code as yours. Same error alerted. And I just created a new project and do npm install @react-pdf/renderer again. Other error pops up image

Really thanks for the help!

diegomura commented 5 years ago

That last error is due to https://github.com/diegomura/react-pdf/commit/9d8903ed73bcbcd3e01065635d81225901cbdcaa

Will be published in next version. The other issue had nothing to do with it, and seems to me that does not occur anymore. Going to publish the new version now and please try with it

markusjohnsson commented 5 years ago

@diegomura I'm seeing this error too (the initial one, with getCurrentStack) when using webpack with mode=development, however, it goes away with mode=production.

zhonggithub commented 4 years ago

same issue

russgove commented 4 years ago

same issue here

syriaca commented 4 years ago

same issue, the problem is still there @diegomura

syriaca commented 4 years ago

Hi, is there any chances to fix that at any times ? I can't get that work in Reactjs.net environment @diegomura .

kishore075 commented 4 years ago

Hi @diegomura

Using exactly same code as yours just to create sample one but still no luck

Error: Cannot set property 'getCurrentStack' of undefined

Can you please suggest

Fareedbaba commented 3 years ago

installed the version 1.6.9 and created a sample application and encountering this error am not sure if this issue was fixed

Can you please suggest any solution here

diegomura commented 3 years ago

For the ones getting this error, do you mind checking what React version are you using? I still suspect there's something conflicting with the React version since the error is on react-reconciler

Fareedbaba commented 3 years ago

Hello @diegomura Am using "react": "16.8.5", version, "react-dom": "16.8.5", Can you please suggest any solution to address the issue

diegomura commented 3 years ago

Can you provide a way to replicate it? I would be happy to fix this but I as I said above, I can't replicate it on my side

Fareedbaba commented 3 years ago

Hello @diegomura , Thanks for your reply

am creating a spfx webpart following is the reference: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part then am installing the react-pdf package using "npm i @react-pdf/renderer" then am adding a small piece of code <PDFDownloadLink document={} fileName="somename.pdf"> {(loading) => (loading ? 'Loading document...' : 'Download now!')} when am running the code, this ends up into a endless loop throwing the error in react-reconciler

your help on this would be highly valuable for me here

diegomura commented 3 years ago

But you are not providing any document into the document prop in there. Do you mind expanding?

Dangerous-Mind commented 3 years ago

@diegomura I was having the same problem. I think it's because he might be saving the pdf with the inside of it. So it enters a loop.

Anyway it hangs without any message when I trying to print a small test message.

const MyDoc = () => (
  <Document>
    <Page>
      <Text>Hellow World</Text>
    </Page>
  </Document>
)

Is there any special thing to do in SPFx?

@Fareedbaba Did you managed to solve your issue?

PS: Digging in to the loop I find the same error "Cannot set property 'getCurrentStack' of undefined"

function resetCurrentFiber() {
  {
    ReactDebugCurrentFrame.getCurrentStack = null;
    current = null;
    phase = null;
  }
}

ReactDebugCurrentFrame is undefined and that's why it throws the error.

This error only append in debug mode. So, I deployed it to prod and works a little better. It shows a download link and if it is clicked it redirects the user to https://contoso.sharepoint.com/sites/Sitename/blob:/50fe4a02-5d0d-44e9-9970-c9a3e088dbae

And since SharePoint does not recognize that page it throws a page not found

diegomura commented 3 years ago

Can someone test if this persist on 2.0? Thank you!!

diegomura commented 3 years ago

I still cannot replicate it. Any help from someone who can test it? Or someone who provides a valid snippet to replicate it?

tkreis commented 3 years ago

Similar to @Dangerous-Mind experience, this has started to pop up in a project of mine as well. In our case it was related to us loading an production build of react and setting the env to development.

Thus causing the error inside of the react-reconciler. So at least in our case it wasn't a bug of pdf-react.

no-response[bot] commented 3 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.