diegomura / react-pdf

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

Support for React 19 #2912

Open wkigenyi opened 1 week ago

wkigenyi commented 1 week ago

Hi,

Thanks for the wonderful library. It works well with <= React v18. Is there a plan to support React 19?

ck-euan commented 1 week ago

This PR updates the package for react 19 (https://github.com/diegomura/react-pdf/pull/2783). You could temporarily use the forked package to get it working now @alexandernanberg/react-pdf-renderer

wkigenyi commented 1 week ago

Thanks I will try it.

wkigenyi commented 1 week ago

This PR updates the package for react 19 (https://github.com/diegomura/react-pdf/pull/2783). You could temporarily use the forked package to get it working now @alexandernanberg/react-pdf-renderer

I have forked your repo. But for some reason the cloning process timeouts before completing. If I succeed with the cloning, could guide me on how I can import the package into my react project?

ck-euan commented 1 week ago

This PR updates the package for react 19 (#2783). You could temporarily use the forked package to get it working now @alexandernanberg/react-pdf-renderer

I have forked your repo. But for some reason the cloning process timeouts before completing. If I succeed with the cloning, could guide me on how I can import the package into my react project?

@wkigenyi The easiest way would be to just install @alexandernanberg/react-pdf-renderer and simply replace any of the imports to use that instead

wkigenyi commented 1 week ago

Thank you.

jpainam commented 5 days ago

Does @alexandernanberg/react-pdf-renderer support Nextjs 15?

wkigenyi commented 5 days ago

Yes it does

pedro757 commented 5 days ago

Have any of you guys run into this issue? @ck-euan @wkigenyi

details: @alexandernanberg/react-pdf-renderer@4.0.0-canary-3 next@15.0.2

Error: ⨯ TypeError: Cannot read properties of undefined (reading 'S')

ck-euan commented 5 days ago

@pedro757 Yeah I just ran into that issue. I believe that the PR needs to be updated with newer versions of react, react-dom and react-reconciler.

I was able to solve it by patching @react-pdf/renderer.

Basically I just copied all of the changes made in https://github.com/diegomura/react-pdf/pull/2783 but I updated the versions to the following: react: 19.0.0-rc-02c0e824-20241028 react-dom: 19.0.0-rc-02c0e824-20241028 react-reconciler: 0.31.0-rc-02c0e824-20241028

Specifically, the exact steps I took to do this were:

  1. Cloned https://github.com/diegomura/react-pdf/pull/2783 locally
  2. Updated react, react-dom and react-reconciler to their latest rc versions
  3. Ran yarn build to build the @react-pdf/renderer packages locally, this gives you the lib folder. We will need to copy this for our patch.
  4. I'm using pnpm so I was able to run pnpm patch @react-pdf/renderer@4.0.0 however you can do the same with patch package if you don't use pnpm
  5. The changes I made for the patch were to replace the existing lib folder from @react-pdf/renderer with the new one I built locally.
  6. Saved the patch with pnpm patch-commit ...

It then started to work for me. I really hope react 19 stable release happens soon 😅

jpainam commented 5 days ago

Yes it does

No, it's doesn't work with nextjs 15 and react 19. I get this error now

@wkigenyi

⨯ TypeError: Cannot read properties of undefined (reading 'S')
    at module.exports (.next/server/chunks/08b5e_@alexandernanberg_react-pdf-renderer_lib_react-pdf_1362ba.js:14494:67)
    at createRenderer (.next/server/chunks/08b5e_@alexandernanberg_react-pdf-renderer_lib_react-pdf_1362ba.js:14980:12)
    at pdf (/.next/server/chunks/08b5e_@alexandernanberg_react-pdf-renderer_lib_react-pdf_1362ba.js:15180:28)
    at renderToStream (/.next/server/chunks/08b5e_@alexandernanberg_react-pdf-renderer_lib_react-pdf_1362ba.js:15311:22)
wkigenyi commented 5 days ago

It worked for me and still works. How did you install yours?

sam3d commented 5 days ago

@wkigenyi is there any chance you could share your package.json and lockfile?

wkigenyi commented 5 days ago

This good pointer. I have remembered that I actually have 2 packages "@alexandernanberg/react-pdf-renderer": "4.0.0-canary-3" and "@react-pdf/renderer": "^4.0.0". I imported the PDFDownloadLink from "@alexander..." the components and other functions from "@react-pdf/renderer"

jpainam commented 5 days ago

@alexandernanberg/react-pdf-renderer

Installed using pnpm add @alexandernanberg/react-pdf-renderer. Got this in my package.json "@alexandernanberg/react-pdf-renderer": "4.0.0-canary-3", i'm server rendering, so i'm using renderToStream

pedro757 commented 5 days ago

Specifically, the exact steps I took to do this were:

Thank you @ck-euan !, That works, good workaround.

wkigenyi commented 4 days ago

This good pointer. I have remembered that I actually have 2 packages "@alexandernanberg/react-pdf-renderer": "4.0.0-canary-3" and "@react-pdf/renderer": "^4.0.0". I imported the PDFDownloadLink from "@alexander..." the components and other functions from "@react-pdf/renderer"

@sam3d did this work for you ?

wkigenyi commented 23 hours ago

@ck-euan I sometimes run into this error on re-rendering TypeError: detachDeletedInstance is not a function