diegomura / react-pdf

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

Using React 19 + Reconciler 0.31 breaks in production (Vercel) #2966

Closed Jussinevavuori closed 1 week ago

Jussinevavuori commented 1 week ago

Describe the bug @react-pdf/renderer@4.1.4 with React 19 and React Reconciler 0.31 breaks in production environment with the following error message from the reconciler.

TypeError: Cannot read properties of undefined (reading 'S')
    at process.env.NODE_ENV.a.exports.l.exports (../../node_modules/@react-pdf/reconciler/lib/reconciler-31.js:10:88446)
    at k (../../node_modules/@react-pdf/reconciler/lib/reconciler-31.js:19:1068)
    at createRenderer (../../node_modules/@react-pdf/renderer/lib/react-pdf.js:85:10)
    at pdf (../../node_modules/@react-pdf/renderer/lib/react-pdf.js:210:26)
    at renderToStream (../../node_modules/@react-pdf/renderer/lib/react-pdf.js:368:20)
    at renderToBuffer (../../node_modules/@react-pdf/renderer/lib/react-pdf.js:395:35)
    at m (/var/task/apps/web/.next/server/chunks/7570.js:1:909)
    at async (/var/task/apps/web/.next/server/chunks/7570.js:1:27806)
    at async u.middlewares (/var/task/apps/web/.next/server/chunks/5151.js:2737:12109)

To Reproduce

  1. Create new Next.js app
bun create next-app@latest
  1. Create route handler at any endpoint.
import { renderToBuffer, Document, Page, Text } from "@react-pdf/renderer";

const MinimalPdfDocument = () => (
  <Document>
    <Page style={{}}>
      <Text style={{}} fixed>
        Test
      </Text>
    </Page>
  </Document>
);

export async function GET() {
  const document = <MinimalPdfDocument />;
  const buffer = await renderToBuffer(document);
  return new Response(buffer, {
    headers: { "Content-Type": "application/pdf" },
  });
}
  1. Deploy to Vercel
  2. Access endpoint

Expected behavior No error.

Screenshots None.

Desktop (please complete the following information):

Jussinevavuori commented 1 week ago

Nevermind. These were caused by my own patches (see more #2964) causing mismatching versions of React and the Reconciler.

If you see this error, ensure all React versions match. Do not override the isReact19 check in @react-pdf/reconciler/lib/index.js.